Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Move 512-bit distribution quality check to slow-tests
Better assertion-failure text
  • Loading branch information
dvdplm committed Nov 25, 2024
1 parent 5ce9bf9 commit 66b37ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/hazmat/uniform_sieve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,31 +339,31 @@ mod tests {
fn uniform_sieve_primes() {
let p: U64 = U64::generate_prime();
info!("64 bit prime={p:?}");
assert!(is_prime(&p));
assert!(is_prime_with_rng(&mut OsRng, &p));

let p = U128::generate_prime();
info!("128 bit prime={p:?}");
assert!(is_prime(&p));
assert!(is_prime_with_rng(&mut OsRng, &p));

let p = U256::generate_prime();
info!("256 bit prime={p:?}");
assert!(is_prime(&p));
assert!(is_prime_with_rng(&mut OsRng, &p));

let p = U512::generate_prime();
info!("512 bit prime={p:?}");
assert!(is_prime(&p));
assert!(is_prime_with_rng(&mut OsRng, &p));

let p = U1024::generate_prime();
info!("1024 bit prime={p:?}");
assert!(is_prime(&p));
assert!(is_prime_with_rng(&mut OsRng, &p));

let p = U2048::generate_prime();
info!("2048 bit prime={p:?}");
assert!(is_prime(&p));
assert!(is_prime_with_rng(&mut OsRng, &p));
// // This is very slow
// let p = U4096::generate_prime();
// info!("4096 bit prime={p:?}");
// assert!(is_prime(&p));
// assert!(is_prime_with_rng(&mut OsRng, &p));
}

#[test_log::test]
Expand All @@ -378,6 +378,7 @@ mod tests {
fn check_distribution_quality_u256() {
check_distribution_quality::<U256>();
}
#[cfg(feature = "tests-exhaustive")]
#[test_log::test]
fn check_distribution_quality_u512() {
check_distribution_quality::<U512>();
Expand Down
2 changes: 1 addition & 1 deletion src/stat_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
"Sampled {sample_count} {} bit primes. p={p_value}, chi_squared={chi_square_stat}",

Check warning on line 25 in src/stat_utils.rs

View check run for this annotation

Codecov / codecov/patch

src/stat_utils.rs#L25

Added line #L25 was not covered by tests
T::BITS
);
assert!(p_value > 0.05);
assert!(p_value > 0.05, "Expected a p_value larger than 0.05, instead found {p_value}, failing to prove that the distribution is uniform.");
assert!(chi_square_stat < 16.92, "For p 0.05, the critical chi-square value is 16.92, instead we got {chi_square_stat}, failing the hypothesis that the distribution is uniform.");
}

Expand Down

0 comments on commit 66b37ae

Please sign in to comment.