From dba4099652f0a6af50d813581f1756a46f967ac6 Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Tue, 24 Jan 2023 12:32:15 -0800 Subject: [PATCH] Add more robust quality test (#151) * Test more combinations Signed-off-by: Tom Kaitchuck --- src/hash_quality_test.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/hash_quality_test.rs b/src/hash_quality_test.rs index bd85edd..8f13d24 100644 --- a/src/hash_quality_test.rs +++ b/src/hash_quality_test.rs @@ -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, combinations: &mut Vec>) { +fn gen_combinations(options: &[u32; 11], depth: u32, so_far: Vec, combinations: &mut Vec>) { if depth == 0 { return; } @@ -63,8 +63,9 @@ fn gen_combinations(options: &[u32; 8], depth: u32, so_far: Vec, combinatio } fn test_no_full_collisions(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); @@ -89,7 +90,7 @@ fn test_no_full_collisions(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(constructor: impl Fn(u128, u128) -> T) { @@ -150,9 +151,10 @@ fn assert_each_byte_differs(num: u64, base: u64, alternitives: Vec) { assert_eq!( core::u64::MAX, changed_bits, - "Bits changed: {:x} on num: {:?}", + "Bits changed: {:x} on num: {:?}. base {:x}", changed_bits, - num + num, + base ); }