From ab174bb857f650885560f4b86121f382941706ac Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sat, 15 Jun 2024 14:41:28 +0200 Subject: [PATCH] chore: remove TODOs about proptest cases --- src/algorithms/gcd/matrix.rs | 4 +--- src/algorithms/gcd/mod.rs | 10 ++-------- src/bits.rs | 2 +- src/gcd.rs | 5 +---- src/modular.rs | 17 ++++++++--------- 5 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/algorithms/gcd/matrix.rs b/src/algorithms/gcd/matrix.rs index b2138f5a..3d637364 100644 --- a/src/algorithms/gcd/matrix.rs +++ b/src/algorithms/gcd/matrix.rs @@ -445,9 +445,7 @@ mod tests { const_for!(BITS in SIZES { const LIMBS: usize = nlimbs(BITS); type U = Uint; - // 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); }); diff --git a/src/algorithms/gcd/mod.rs b/src/algorithms/gcd/mod.rs index a7d2114d..0898bfef 100644 --- a/src/algorithms/gcd/mod.rs +++ b/src/algorithms/gcd/mod.rs @@ -191,7 +191,6 @@ pub fn inv_mod( mod tests { use super::*; use crate::{const_for, nlimbs}; - use core::cmp::min; use proptest::{proptest, test_runner::Config}; #[test] @@ -223,9 +222,7 @@ mod tests { const_for!(BITS in SIZES { const LIMBS: usize = nlimbs(BITS); type U = Uint; - // 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)); }); @@ -233,14 +230,11 @@ mod tests { } #[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; - // 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)); diff --git a/src/bits.rs b/src/bits.rs index 119804a9..eb2a40b5 100644 --- a/src/bits.rs +++ b/src/bits.rs @@ -840,7 +840,7 @@ mod tests { type U = Uint::; 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) diff --git a/src/gcd.rs b/src/gcd.rs index a18bf0c2..1667c85c 100644 --- a/src/gcd.rs +++ b/src/gcd.rs @@ -53,7 +53,6 @@ impl Uint { mod tests { use super::*; use crate::{const_for, nlimbs}; - use core::cmp::min; use proptest::{proptest, test_runner::Config}; #[test] @@ -62,9 +61,7 @@ mod tests { const_for!(BITS in SIZES { const LIMBS: usize = nlimbs(BITS); type U = Uint; - // 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); diff --git a/src/modular.rs b/src/modular.rs index 3970b520..1f94955b 100644 --- a/src/modular.rs +++ b/src/modular.rs @@ -176,7 +176,6 @@ impl Uint { mod tests { use super::*; use crate::{aliases::U64, const_for, nlimbs}; - use core::cmp::min; use proptest::{prop_assume, proptest, test_runner::Config}; #[test] @@ -252,10 +251,13 @@ mod tests { const_for!(BITS in NON_ZERO { const LIMBS: usize = nlimbs(BITS); type U = Uint; - // 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. @@ -269,10 +271,7 @@ mod tests { const_for!(BITS in NON_ZERO { const LIMBS: usize = nlimbs(BITS); type U = Uint; - // 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)); }