Skip to content

Commit 71de84e

Browse files
committed
Add a test that different seeds cause different hashes
1 parent 3a5e0c4 commit 71de84e

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
@@ -286,4 +286,29 @@ mod tests {
286286
hash(HashBytes(b"These are some bytes for testing rustc_hash.")) == if B32 { 2345708736 } else { 12390864548135261390 },
287287
}
288288
}
289+
290+
#[test]
291+
fn with_seed_actually_different() {
292+
let seeds = [
293+
[1, 2],
294+
[42, 17],
295+
[124436707, 99237],
296+
[usize::MIN, usize::MAX],
297+
];
298+
299+
for [a_seed, b_seed] in seeds {
300+
let a = || FxHasher::with_seed(a_seed);
301+
let b = || FxHasher::with_seed(b_seed);
302+
303+
for x in u8::MIN..=u8::MAX {
304+
let mut a = a();
305+
let mut b = b();
306+
307+
x.hash(&mut a);
308+
x.hash(&mut b);
309+
310+
assert_ne!(a.finish(), b.finish())
311+
}
312+
}
313+
}
289314
}

0 commit comments

Comments
 (0)