Skip to content

Commit

Permalink
Fix test test_hash (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexoooooo authored May 9, 2024
1 parent b079a9b commit d0f49bc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{smallvec, SmallVec};

use core::hash::Hasher;
use core::iter::FromIterator;

use alloc::borrow::ToOwned;
Expand Down Expand Up @@ -600,19 +601,24 @@ fn test_hash() {
use std::collections::hash_map::DefaultHasher;
use std::hash::Hash;

fn hash(value: impl Hash) -> u64 {
let mut hasher = DefaultHasher::new();
value.hash(&mut hasher);
hasher.finish()
}

{
let mut a: SmallVec<u32, 2> = SmallVec::new();
let b = [1, 2];
a.extend(b.iter().cloned());
let mut hasher = DefaultHasher::new();
assert_eq!(a.hash(&mut hasher), b.hash(&mut hasher));
assert_eq!(hash(a), hash(b));
}

{
let mut a: SmallVec<u32, 2> = SmallVec::new();
let b = [1, 2, 11, 12];
a.extend(b.iter().cloned());
let mut hasher = DefaultHasher::new();
assert_eq!(a.hash(&mut hasher), b.hash(&mut hasher));
assert_eq!(hash(a), hash(b));
}
}

Expand Down

0 comments on commit d0f49bc

Please sign in to comment.