2019-04-07 17:17:43 -05:00
|
|
|
// compile-flags: -Zmiri-seed=0000000000000000
|
|
|
|
|
2017-06-02 20:35:33 -05:00
|
|
|
use std::collections::{self, HashMap};
|
2019-04-07 17:17:43 -05:00
|
|
|
use std::hash::{BuildHasherDefault, BuildHasher};
|
2017-06-02 20:35:33 -05:00
|
|
|
|
2019-04-07 17:17:43 -05:00
|
|
|
fn test_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
|
2017-06-22 02:12:47 -05:00
|
|
|
map.insert(0, 0);
|
2017-06-02 20:35:33 -05:00
|
|
|
assert_eq!(map.values().fold(0, |x, y| x+y), 0);
|
|
|
|
|
2017-06-22 02:12:47 -05:00
|
|
|
let table_base = map.get(&0).unwrap() as *const _;
|
|
|
|
|
|
|
|
let num = 22; // large enough to trigger a resize
|
|
|
|
for i in 1..num {
|
|
|
|
map.insert(i, i);
|
|
|
|
}
|
|
|
|
assert!(table_base != map.get(&0).unwrap() as *const _); // make sure relocation happened
|
|
|
|
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);
|
2017-06-02 20:35:33 -05:00
|
|
|
|
2019-02-13 10:21:46 -06:00
|
|
|
// TODO: Test Entry API, Iterators, ...
|
2019-04-07 17:17:43 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-04-08 21:48:57 -05:00
|
|
|
if cfg!(not(target_os = "macos")) {
|
2019-04-16 12:06:08 -05:00
|
|
|
let map: HashMap<i32, i32> = HashMap::default();
|
|
|
|
test_map(map);
|
2019-04-08 21:29:40 -05:00
|
|
|
} else {
|
2019-04-16 12:06:08 -05:00
|
|
|
// TODO: Implement random number generation on OS X.
|
|
|
|
// Until then, use a deterministic map.
|
|
|
|
let map : HashMap<i32, i32, BuildHasherDefault<collections::hash_map::DefaultHasher>> = HashMap::default();
|
2019-04-09 22:36:27 -05:00
|
|
|
test_map(map);
|
2019-04-08 21:29:40 -05:00
|
|
|
}
|
2017-06-02 20:35:33 -05:00
|
|
|
}
|