Skip to content

Commit

Permalink
Add a test that different seeds cause different hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Jan 17, 2024
1 parent 6fd6a8a commit b9ca726
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
}

0 comments on commit b9ca726

Please sign in to comment.