@@ -672,6 +672,10 @@ mod tests {
672
672
let kv2 = KeyValue :: new ( "key" , std:: f64:: INFINITY ) ;
673
673
assert_eq ! ( kv1, kv2) ;
674
674
675
+ let kv1 = KeyValue :: new ( "key" , std:: f64:: NEG_INFINITY ) ;
676
+ let kv2 = KeyValue :: new ( "key" , std:: f64:: NEG_INFINITY ) ;
677
+ assert_eq ! ( kv1, kv2) ;
678
+
675
679
let mut rng = rand:: thread_rng ( ) ;
676
680
677
681
for _ in 0 ..100 {
@@ -692,6 +696,10 @@ mod tests {
692
696
let kv2 = KeyValue :: new ( "key" , 1.001 ) ;
693
697
assert_eq ! ( hash_helper( & kv1) , hash_helper( & kv2) ) ;
694
698
699
+ let kv1 = KeyValue :: new ( "key" , 1.001 ) ;
700
+ let kv2 = KeyValue :: new ( "key" , 1.002 ) ;
701
+ assert_ne ! ( hash_helper( & kv1) , hash_helper( & kv2) ) ;
702
+
695
703
let kv1 = KeyValue :: new ( "key" , std:: f64:: NAN ) ;
696
704
let kv2 = KeyValue :: new ( "key" , std:: f64:: NAN ) ;
697
705
assert_eq ! ( hash_helper( & kv1) , hash_helper( & kv2) ) ;
@@ -710,6 +718,23 @@ mod tests {
710
718
}
711
719
}
712
720
721
+ #[ test]
722
+ fn hash_kv_order ( ) {
723
+ let kv1 = KeyValue :: new ( "a" , 1.0 ) ;
724
+ let kv2 = KeyValue :: new ( "b" , 1.0 ) ;
725
+ assert ! ( kv1 < kv2) ;
726
+
727
+ let float_vals = [
728
+ 0.0 , 1.0 , -1.0 , std:: f64:: INFINITY , std:: f64:: NEG_INFINITY , std:: f64:: NAN , std:: f64:: MIN , std:: f64:: MAX ,
729
+ ] ;
730
+
731
+ for v in float_vals {
732
+ let kv1 = KeyValue :: new ( "a" , v) ;
733
+ let kv2 = KeyValue :: new ( "b" , v) ;
734
+ assert ! ( kv1 < kv2, "Order is solely based on key!" ) ;
735
+ }
736
+ }
737
+
713
738
fn hash_helper < T : Hash > ( item : & T ) -> u64 {
714
739
let mut hasher = DefaultHasher :: new ( ) ;
715
740
item. hash ( & mut hasher) ;
0 commit comments