diff options
author | Son Ho | 2022-02-07 13:42:52 +0100 |
---|---|---|
committer | Son Ho | 2022-02-07 13:42:52 +0100 |
commit | b9e35316426f09d07810f4f7eff3ca2dddd1d264 (patch) | |
tree | aaa31712f603c71a17fb980f5e033aae66395bd7 | |
parent | 1bbaa008f31367fb2c2e28c76da6bb5ecdcb6c1b (diff) |
Add tests for the hashmap
-rw-r--r-- | examples/misc/src/hashmap.rs | 15 | ||||
-rw-r--r-- | examples/misc/src/main.rs | 4 |
2 files changed, 16 insertions, 3 deletions
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<T> HashMap<T> { HashMap::remove_from_list(key, self.slots.get_mut(hash_mod).unwrap()) } } + +#[test] +fn test1() { + let mut hm: HashMap<u64> = 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<u64> = HashMap::new(); -} +fn main() {} |