Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CoCo-Japan-pan committed Jan 12, 2025
1 parent bf881ff commit 27d3ad7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions crates/misc/doubling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,24 @@ mod test {
assert_eq!(doubling.query(index, x as u64), expected);
}
}

#[test]
fn test_two_beki() {
let mut rng = thread_rng();
const SIZE: usize = 1024;
let func = (0..SIZE)
.map(|_| rng.gen_range(0..SIZE))
.collect::<Vec<_>>();
let max_pow = 1024;
let doubling = Doubling::new(&func, max_pow);
for bit in 0..=10 {
let index = rng.gen_range(0..SIZE);
let x = 1 << bit;
let expected = (0..x).fold(index, |i, _| func[i]);
assert_eq!(doubling.query(index, x as u64), expected);
let x = x - 1;
let expected = (0..x).fold(index, |i, _| func[i]);
assert_eq!(doubling.query(index, x as u64), expected);
}
}
}

0 comments on commit 27d3ad7

Please sign in to comment.