1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-04 23:17:46 +00:00

factor::miller_rabin: Use a macro to instantiate every test

This commit is contained in:
nicoo 2020-07-04 23:48:01 +02:00
parent 7a1b86c9c2
commit 6256750376

View file

@ -146,21 +146,28 @@ mod tests {
assert!(is_prime(2)); assert!(is_prime(2));
} }
// TODO: Deduplicate with macro in numeric.rs
macro_rules! parametrized_check {
( $f:ident ) => {
paste::item! {
#[test]
fn [< $f _ u32 >]() {
$f::<Montgomery<u32>>()
}
#[test]
fn [< $f _ u64 >]() {
$f::<Montgomery<u64>>()
}
}
};
}
fn first_primes<A: Arithmetic + Basis>() { fn first_primes<A: Arithmetic + Basis>() {
for p in odd_primes() { for p in odd_primes() {
assert!(test(A::new(p)).is_prime(), "{} reported composite", p); assert!(test(A::new(p)).is_prime(), "{} reported composite", p);
} }
} }
parametrized_check!(first_primes);
#[test]
fn first_primes_32() {
first_primes::<Montgomery<u32>>()
}
#[test]
fn first_primes_64() {
first_primes::<Montgomery<u64>>()
}
#[test] #[test]
fn one() { fn one() {
@ -178,16 +185,7 @@ mod tests {
} }
} }
} }
parametrized_check!(first_composites);
#[test]
fn first_composites_32() {
first_composites::<Montgomery<u32>>()
}
#[test]
fn first_composites_64() {
first_composites::<Montgomery<u64>>()
}
#[test] #[test]
fn issue_1556() { fn issue_1556() {
@ -204,16 +202,7 @@ mod tests {
} }
} }
} }
parametrized_check!(small_semiprimes);
#[test]
fn small_semiprimes_32() {
small_semiprimes::<Montgomery<u32>>()
}
#[test]
fn small_semiprimes_64() {
small_semiprimes::<Montgomery<u64>>()
}
quickcheck! { quickcheck! {
fn composites(i: u64, j: u64) -> bool { fn composites(i: u64, j: u64) -> bool {