Skip to content

Commit 2c88765

Browse files
jogru0mbrubeck
authored andcommitted
add unit tests for hash codes of special values
1 parent d513f95 commit 2c88765

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tests/test.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ fn not_nan64_num_cast() {
456456
}
457457

458458
#[test]
459-
fn hash_zero_and_neg_zero_to_the_same_hc() {
459+
fn hash_zero_and_neg_zero_to_the_same_hc_ordered_float64() {
460460
let state = RandomState::new();
461461
let mut h1 = state.build_hasher();
462462
let mut h2 = state.build_hasher();
@@ -465,6 +465,26 @@ fn hash_zero_and_neg_zero_to_the_same_hc() {
465465
assert_eq!(h1.finish(), h2.finish());
466466
}
467467

468+
#[test]
469+
fn hash_zero_and_neg_zero_to_the_same_hc_not_nan32() {
470+
let state = RandomState::new();
471+
let mut h1 = state.build_hasher();
472+
let mut h2 = state.build_hasher();
473+
NotNan::try_from(0f32).unwrap().hash(&mut h1);
474+
NotNan::try_from(-0f32).unwrap().hash(&mut h2);
475+
assert_eq!(h1.finish(), h2.finish());
476+
}
477+
478+
#[test]
479+
fn hash_different_nans_to_the_same_hc() {
480+
let state = RandomState::new();
481+
let mut h1 = state.build_hasher();
482+
let mut h2 = state.build_hasher();
483+
OrderedFloat::from(f64::nan()).hash(&mut h1);
484+
OrderedFloat::from(-f64::nan()).hash(&mut h2);
485+
assert_eq!(h1.finish(), h2.finish());
486+
}
487+
468488
#[test]
469489
fn hash_inf_and_neg_inf_to_different_hcs() {
470490
let state = RandomState::new();

0 commit comments

Comments
 (0)