Skip to content

Commit

Permalink
Use random hasher state for number hashing test
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 28, 2023
1 parent fe031cd commit 7ff6c9e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ use serde_json::{
from_reader, from_slice, from_str, from_value, json, to_string, to_string_pretty, to_value,
to_vec, Deserializer, Number, Value,
};
use std::collections::hash_map::DefaultHasher;
use std::collections::BTreeMap;
#[cfg(feature = "raw_value")]
use std::collections::HashMap;
use std::fmt::{self, Debug};
use std::hash::{Hash, Hasher};
use std::hash::{BuildHasher, Hash, Hasher};
use std::io;
use std::iter;
use std::marker::PhantomData;
Expand Down Expand Up @@ -2490,11 +2489,12 @@ fn test_value_into_deserializer() {

#[test]
fn hash_positive_and_negative_zero() {
fn hash(obj: impl Hash) -> u64 {
let mut hasher = DefaultHasher::new();
let rand = std::hash::RandomState::new();
let hash = |obj: Number| -> u64 {
let mut hasher = rand.build_hasher();
obj.hash(&mut hasher);
hasher.finish()
}
};

let k1 = serde_json::from_str::<Number>("0.0").unwrap();
let k2 = serde_json::from_str::<Number>("-0.0").unwrap();
Expand Down

0 comments on commit 7ff6c9e

Please sign in to comment.