Skip to content

Commit dba4099

Browse files
authored
Add more robust quality test (#151)
* Test more combinations Signed-off-by: Tom Kaitchuck <[email protected]>
1 parent fa13faf commit dba4099

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/hash_quality_test.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn count_same_bytes_and_nibbles(a: u64, b: u64) -> (i32, i32) {
5050
(same_byte_count, same_nibble_count)
5151
}
5252

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

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

9596
fn test_keys_change_output<T: Hasher>(constructor: impl Fn(u128, u128) -> T) {
@@ -150,9 +151,10 @@ fn assert_each_byte_differs(num: u64, base: u64, alternitives: Vec<u64>) {
150151
assert_eq!(
151152
core::u64::MAX,
152153
changed_bits,
153-
"Bits changed: {:x} on num: {:?}",
154+
"Bits changed: {:x} on num: {:?}. base {:x}",
154155
changed_bits,
155-
num
156+
num,
157+
base
156158
);
157159
}
158160

0 commit comments

Comments
 (0)