From 6256750376f476fe8b48800bcf9b7dee0642559a Mon Sep 17 00:00:00 2001 From: nicoo Date: Sat, 4 Jul 2020 23:48:01 +0200 Subject: [PATCH] factor::miller_rabin: Use a macro to instantiate every test --- src/uu/factor/src/miller_rabin.rs | 49 ++++++++++++------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/src/uu/factor/src/miller_rabin.rs b/src/uu/factor/src/miller_rabin.rs index 04649fa72..762ee1b4c 100644 --- a/src/uu/factor/src/miller_rabin.rs +++ b/src/uu/factor/src/miller_rabin.rs @@ -146,21 +146,28 @@ mod tests { assert!(is_prime(2)); } + // TODO: Deduplicate with macro in numeric.rs + macro_rules! parametrized_check { + ( $f:ident ) => { + paste::item! { + #[test] + fn [< $f _ u32 >]() { + $f::>() + } + #[test] + fn [< $f _ u64 >]() { + $f::>() + } + } + }; + } + fn first_primes() { for p in odd_primes() { assert!(test(A::new(p)).is_prime(), "{} reported composite", p); } } - - #[test] - fn first_primes_32() { - first_primes::>() - } - - #[test] - fn first_primes_64() { - first_primes::>() - } + parametrized_check!(first_primes); #[test] fn one() { @@ -178,16 +185,7 @@ mod tests { } } } - - #[test] - fn first_composites_32() { - first_composites::>() - } - - #[test] - fn first_composites_64() { - first_composites::>() - } + parametrized_check!(first_composites); #[test] fn issue_1556() { @@ -204,16 +202,7 @@ mod tests { } } } - - #[test] - fn small_semiprimes_32() { - small_semiprimes::>() - } - - #[test] - fn small_semiprimes_64() { - small_semiprimes::>() - } + parametrized_check!(small_semiprimes); quickcheck! { fn composites(i: u64, j: u64) -> bool {