From ae09d83c0a0bdebaf87154c6966a63fd780d9f88 Mon Sep 17 00:00:00 2001 From: Lexo Liu Date: Fri, 10 May 2024 01:04:32 +0800 Subject: [PATCH] Fix test `test_hash` --- src/tests.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/tests.rs b/src/tests.rs index 2f1522c..1b766c2 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,5 +1,6 @@ use crate::{smallvec, SmallVec}; +use core::hash::Hasher; use core::iter::FromIterator; use alloc::borrow::ToOwned; @@ -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 = 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 = 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)); } }