Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more robust quality test #151

Merged
merged 4 commits into from
Jan 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/hash_quality_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn count_same_bytes_and_nibbles(a: u64, b: u64) -> (i32, i32) {
(same_byte_count, same_nibble_count)
}

fn gen_combinations(options: &[u32; 8], depth: u32, so_far: Vec<u32>, combinations: &mut Vec<Vec<u32>>) {
fn gen_combinations(options: &[u32; 11], depth: u32, so_far: Vec<u32>, combinations: &mut Vec<Vec<u32>>) {
if depth == 0 {
return;
}
Expand All @@ -63,8 +63,9 @@ fn gen_combinations(options: &[u32; 8], depth: u32, so_far: Vec<u32>, combinatio
}

fn test_no_full_collisions<T: Hasher>(gen_hash: impl Fn() -> T) {
let options: [u32; 8] = [
0x00000000, 0x20000000, 0x40000000, 0x60000000, 0x80000000, 0xA0000000, 0xC0000000, 0xE0000000,
let options: [u32; 11] = [
0x00000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0xF0000000,
1, 2, 4, 8, 15
];
let mut combinations = Vec::new();
gen_combinations(&options, 7, Vec::new(), &mut combinations);
Expand All @@ -89,7 +90,7 @@ fn test_no_full_collisions<T: Hasher>(gen_hash: impl Fn() -> T) {
map.insert(hash, array);
}
}
assert_eq!(2396744, map.len());
assert_eq!(21435887, map.len()); //11^7 + 11^6 ...
}

fn test_keys_change_output<T: Hasher>(constructor: impl Fn(u128, u128) -> T) {
Expand Down Expand Up @@ -150,9 +151,10 @@ fn assert_each_byte_differs(num: u64, base: u64, alternitives: Vec<u64>) {
assert_eq!(
core::u64::MAX,
changed_bits,
"Bits changed: {:x} on num: {:?}",
"Bits changed: {:x} on num: {:?}. base {:x}",
changed_bits,
num
num,
base
);
}

Expand Down