]> git.lizzy.rs Git - rust.git/blob - tests/run-pass/hashmap.rs
fix tests for latest Rust
[rust.git] / tests / run-pass / hashmap.rs
1 // compile-flags: -Zmiri-seed=0000000000000000
2
3 use std::collections::{self, HashMap};
4 use std::hash::{BuildHasherDefault, BuildHasher};
5
6 fn test_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
7     map.insert(0, 0);
8     assert_eq!(map.values().fold(0, |x, y| x+y), 0);
9
10     let num = 25;
11     for i in 1..num {
12         map.insert(i, i);
13     }
14     assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); // check the right things are in the table now
15
16     // Inserting again replaces the existing entries
17     for i in 0..num {
18         map.insert(i, num-1-i);
19     }
20     assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2);
21
22     // TODO: Test Entry API, Iterators, ...
23
24 }
25
26 fn main() {
27     if cfg!(target_os = "macos") { // TODO: Implement random number generation on OS X.
28         // Until then, use a deterministic map.
29         let map : HashMap<i32, i32, BuildHasherDefault<collections::hash_map::DefaultHasher>> = HashMap::default();
30         test_map(map);
31     } else {
32         let map: HashMap<i32, i32> = HashMap::default();
33         test_map(map);
34     }
35 }