Skip to content

Commit b9ca726

Browse files
committed
Add a test that different seeds cause different hashes
1 parent 6fd6a8a commit b9ca726

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,29 @@ mod tests {
284284
hash(HashBytes(b"These are some bytes for testing rustc_hash.")) == if B32 { 2345708736 } else { 12390864548135261390 },
285285
}
286286
}
287+
288+
#[test]
289+
fn with_seed_actually_different() {
290+
let seeds = [
291+
[1, 2],
292+
[42, 17],
293+
[124436707, 99237],
294+
[usize::MIN, usize::MAX],
295+
];
296+
297+
for [a_seed, b_seed] in seeds {
298+
let a = || FxHasher::with_seed(a_seed);
299+
let b = || FxHasher::with_seed(b_seed);
300+
301+
for x in u8::MIN..=u8::MAX {
302+
let mut a = a();
303+
let mut b = b();
304+
305+
x.hash(&mut a);
306+
x.hash(&mut b);
307+
308+
assert_ne!(a.finish(), b.finish())
309+
}
310+
}
311+
}
287312
}

0 commit comments

Comments
 (0)