rust/tests/run-pass-noseed/hashmap.rs

34 lines
1.0 KiB
Rust
Raw Normal View History

// compile-flags: -Zmiri-seed=0000000000000000
use std::collections::{self, HashMap};
use std::hash::{BuildHasherDefault, BuildHasher};
fn test_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
map.insert(0, 0);
assert_eq!(map.values().fold(0, |x, y| x+y), 0);
2019-05-01 13:43:43 -05:00
let num = 25;
for i in 1..num {
map.insert(i, i);
}
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); // check the right things are in the table now
// Inserting again replaces the existing entries
for i in 0..num {
map.insert(i, num-1-i);
}
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2);
2019-02-13 10:21:46 -06:00
// TODO: Test Entry API, Iterators, ...
}
fn main() {
2019-05-13 04:45:39 -05:00
if cfg!(target_os = "macos") { // TODO: Implement libstd HashMap seeding for macOS (https://github.com/rust-lang/miri/issues/686).
2019-04-16 12:06:08 -05:00
// Until then, use a deterministic map.
2019-05-13 04:45:39 -05:00
test_map::<BuildHasherDefault<collections::hash_map::DefaultHasher>>(HashMap::default());
} else {
2019-05-13 04:45:39 -05:00
test_map(HashMap::new());
}
}