From b9e35316426f09d07810f4f7eff3ca2dddd1d264 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Mon, 7 Feb 2022 13:42:52 +0100 Subject: Add tests for the hashmap --- examples/misc/src/hashmap.rs | 15 +++++++++++++++ examples/misc/src/main.rs | 4 +--- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'examples/misc/src') diff --git a/examples/misc/src/hashmap.rs b/examples/misc/src/hashmap.rs index 98e3f7d8..47a1b150 100644 --- a/examples/misc/src/hashmap.rs +++ b/examples/misc/src/hashmap.rs @@ -166,3 +166,18 @@ impl HashMap { HashMap::remove_from_list(key, self.slots.get_mut(hash_mod).unwrap()) } } + +#[test] +fn test1() { + let mut hm: HashMap = HashMap::new(); + hm.insert(0, 42); + hm.insert(128, 18); + hm.insert(1024, 138); + assert!(*hm.get(&128).unwrap() == 18); + let x = hm.get_mut(&1024).unwrap(); + *x = 56; + assert!(*hm.get(&1024).unwrap() == 56); + assert!(hm.get(&10).is_none()); + let x = hm.remove(&1024).unwrap(); + assert!(x == 56); +} diff --git a/examples/misc/src/main.rs b/examples/misc/src/main.rs index 4587c571..4a984052 100644 --- a/examples/misc/src/main.rs +++ b/examples/misc/src/main.rs @@ -2,6 +2,4 @@ mod hashmap; use hashmap::HashMap; -fn main() { - let hm: HashMap = HashMap::new(); -} +fn main() {} -- cgit v1.2.3