Skip to content

Commit

Permalink
chore: remove TODOs about proptest cases
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Jun 15, 2024
1 parent 0c07a4c commit ab174bb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/algorithms/gcd/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,7 @@ mod tests {
const_for!(BITS in SIZES {
const LIMBS: usize = nlimbs(BITS);
type U = Uint<BITS, LIMBS>;
// TODO: Increase cases when perf is better.
let mut config = Config::default();
config.cases = min(config.cases, if BITS > 500 { 12 } else { 40 });
let config = Config { cases: 10, ..Default::default() };
proptest!(config, |(a: U, b: U)| {
test_form_uint_one(a, b);
});
Expand Down
10 changes: 2 additions & 8 deletions src/algorithms/gcd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ pub fn inv_mod<const BITS: usize, const LIMBS: usize>(
mod tests {
use super::*;
use crate::{const_for, nlimbs};
use core::cmp::min;
use proptest::{proptest, test_runner::Config};

#[test]
Expand Down Expand Up @@ -223,24 +222,19 @@ mod tests {
const_for!(BITS in SIZES {
const LIMBS: usize = nlimbs(BITS);
type U = Uint<BITS, LIMBS>;
// TODO: Increase cases when perf is better.
let mut config = Config::default();
config.cases = min(config.cases, if BITS > 500 { 9 } else { 30 });
let config = Config { cases: 10, ..Default::default()};
proptest!(config, |(a: U, b: U)| {
assert_eq!(gcd(a, b), gcd_ref(a, b));
});
});
}

#[test]
#[allow(clippy::absurd_extreme_comparisons)] // Generated code
fn test_gcd_extended() {
const_for!(BITS in SIZES {
const LIMBS: usize = nlimbs(BITS);
type U = Uint<BITS, LIMBS>;
// TODO: Increase cases when perf is better.
let mut config = Config::default();
config.cases = min(config.cases, if BITS > 500 { 3 } else { 10 });
let config = Config { cases: 5, ..Default::default() };
proptest!(config, |(a: U, b: U)| {
let (g, x, y, sign) = gcd_extended(a, b);
assert_eq!(g, gcd_ref(a, b));
Expand Down
2 changes: 1 addition & 1 deletion src/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ mod tests {
type U = Uint::<BITS, LIMBS>;
proptest!(|(value: U, shift in 0..=BITS + 2)| {
let shifted = value.arithmetic_shr(shift);
dbg!(value, shifted, shift);
// dbg!(value, shifted, shift);
assert_eq!(shifted.leading_ones(), match value.leading_ones() {
0 => 0,
n => min(BITS, n + shift)
Expand Down
5 changes: 1 addition & 4 deletions src/gcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
mod tests {
use super::*;
use crate::{const_for, nlimbs};
use core::cmp::min;
use proptest::{proptest, test_runner::Config};

#[test]
Expand All @@ -62,9 +61,7 @@ mod tests {
const_for!(BITS in SIZES {
const LIMBS: usize = nlimbs(BITS);
type U = Uint<BITS, LIMBS>;
// TODO: Increase cases when perf is better.
let mut config = Config::default();
config.cases = min(config.cases, if BITS > 500 { 3 } else { 10 });
let config = Config { cases: 5, ..Default::default() };
proptest!(config, |(a: U, b: U)| {
let g = a.gcd(b);
assert_eq!(b.gcd(a), g);
Expand Down
17 changes: 8 additions & 9 deletions src/modular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
mod tests {
use super::*;
use crate::{aliases::U64, const_for, nlimbs};
use core::cmp::min;
use proptest::{prop_assume, proptest, test_runner::Config};

#[test]
Expand Down Expand Up @@ -252,10 +251,13 @@ mod tests {
const_for!(BITS in NON_ZERO {
const LIMBS: usize = nlimbs(BITS);
type U = Uint<BITS, LIMBS>;
// TODO: Increase cases when perf is better.
let mut config = Config::default();
// BUG: Proptest still runs 5 cases even if we set it to 1.
config.cases = min(config.cases, if BITS > 500 { 1 } else { 3 });

// Too slow.
if LIMBS > 8 {
return;
}

let config = Config { cases: 5, ..Default::default() };
proptest!(config, |(a: U, b: U, c: U, m: U)| {
// TODO: a^(b+c) = a^b * a^c. Which requires carmichael fn.
// TODO: (a^b)^c = a^(b * c). Which requires carmichael fn.
Expand All @@ -269,10 +271,7 @@ mod tests {
const_for!(BITS in NON_ZERO {
const LIMBS: usize = nlimbs(BITS);
type U = Uint<BITS, LIMBS>;
// TODO: Increase cases when perf is better.
let mut config = Config::default();
config.cases = min(config.cases, if BITS > 500 { 6 } else { 20 });
proptest!(config, |(a: U, m: U)| {
proptest!(|(a: U, m: U)| {
if let Some(inv) = a.inv_mod(m) {
assert_eq!(a.mul_mod(inv, m), U::from(1));
}
Expand Down

0 comments on commit ab174bb

Please sign in to comment.