Skip to content

Commit

Permalink
Calibrate sensitivity and make deterministic
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
  • Loading branch information
tkaitchuck committed Feb 27, 2024
1 parent cd41f90 commit 9d25203
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ fnv = "1.0.5"
fxhash = "0.2.1"
hex = "0.4.2"
rand = "0.8.5"
pcg-mwc = "0.2.1"
serde_json = "1.0.59"
hashbrown = "0.14.3"

Expand Down
18 changes: 14 additions & 4 deletions tests/map_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,18 @@ fn test_key_ref() {
#[cfg(feature = "std")]
#[test]
fn test_byte_dist() {
use rand::{rngs::StdRng, SeedableRng, Rng};
use rand::{SeedableRng, Rng, RngCore};
use pcg_mwc::Mwc256XXA64;

let mut r = StdRng::seed_from_u64(0xe786_c22b_119c_1479);
let mut r = Mwc256XXA64::seed_from_u64(0xe786_c22b_119c_1479);
let mut lowest = 2.541;
let mut highest = 2.541;
for _round in 0..100 {
let mut table: [bool; 256 * 8] = [false; 256 * 8];
let hasher = RandomState::with_seeds(r.gen(), r.gen(), r.gen(), r.gen());
for i in 0..128 {
let mut keys: [u8; 8] = hasher.hash_one(i as u64).to_ne_bytes();
//let mut keys = r.next_u64().to_ne_bytes(); //This is a control to test assert sensitivity.
for idx in 0..8 {
while table[idx * 256 + keys[idx] as usize] {
keys[idx] = keys[idx].wrapping_add(1);
Expand All @@ -259,10 +263,16 @@ fn test_byte_dist() {
}
let mean = total_len as f32 / num_seq as f32;
println!("Mean sequence length = {}", mean);
assert!(mean > 1.70);
assert!(mean < 3.375);
if mean > highest {
highest = mean;
}
if mean < lowest {
lowest = mean;
}
}
}
assert!(lowest > 1.9, "Lowest = {}", lowest);
assert!(highest < 3.9, "Highest = {}", highest);
}


Expand Down

0 comments on commit 9d25203

Please sign in to comment.