Nicer test

This commit is contained in:
Sarah Jamie Lewis 2021-08-15 07:39:04 -07:00
parent 67d16b35fe
commit 4a227c87e4
1 changed files with 10 additions and 16 deletions

View File

@ -222,32 +222,26 @@ mod tests {
use crate::{Generator, Solver, PRIME_ORDER};
use rand::Rng;
use rand_core::OsRng;
use std::collections::HashSet;
#[test]
fn it_works() {
let mut rng = OsRng;
let s = 3u64;
let t = 4u64;
let dhf = Generator::generate(&mut rng, s, t);
let mut attempts = 0;
loop {
let dhf = Generator::generate(&mut rng, s, t);
let mut solver = Solver::new(s, t);
for i in 0..5 {
let mut x0: u64 = rng.gen_range(0..PRIME_ORDER);
let mut solver = Solver::new(s, t);
for i in 0..10 {
// These are the indexes which are to be random...you can try swapping them around..
if i != 5 && i != 2 && i != 8 {
let x0: u64 = rng.gen_range(0..PRIME_ORDER);
let hash = dhf.hash(PrimeOrderDomain::new(x0));
solver.add_hash(hash);
} else {
solver.add_hash(dhf.random(&mut rng));
}
solver.add_hash(dhf.random(&mut rng));
solver.add_hash(dhf.random(&mut rng));
if solver.attempt_solve().is_ok() {
println!("Attempts: {}", attempts);
return;
}
attempts += 1;
}
assert_eq!(solver.attempt_solve().unwrap(), vec![0, 1, 3, 4, 6, 7, 9]);
}
}