diff options
Diffstat (limited to 'examples/misc')
-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() {} |