From b9ca726104b3b774679b61535df1b363a8a93aa7 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 17 Jan 2024 21:11:32 +0100 Subject: [PATCH] Add a test that different seeds cause different hashes --- src/lib.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 107fd12..d704e40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -284,4 +284,29 @@ mod tests { hash(HashBytes(b"These are some bytes for testing rustc_hash.")) == if B32 { 2345708736 } else { 12390864548135261390 }, } } + + #[test] + fn with_seed_actually_different() { + let seeds = [ + [1, 2], + [42, 17], + [124436707, 99237], + [usize::MIN, usize::MAX], + ]; + + for [a_seed, b_seed] in seeds { + let a = || FxHasher::with_seed(a_seed); + let b = || FxHasher::with_seed(b_seed); + + for x in u8::MIN..=u8::MAX { + let mut a = a(); + let mut b = b(); + + x.hash(&mut a); + x.hash(&mut b); + + assert_ne!(a.finish(), b.finish()) + } + } + } }