1 #![cfg(not(miri))] // FIXME: takes too long
2 
3 use hashbrown::HashSet;
4 use rand::{distributions::Alphanumeric, rngs::SmallRng, Rng, SeedableRng};
5 use std::iter;
6 
7 #[test]
test_hashset_insert_remove()8 fn test_hashset_insert_remove() {
9     let mut m: HashSet<Vec<char>> = HashSet::new();
10     let seed = u64::from_le_bytes(*b"testseed");
11 
12     let rng = &mut SmallRng::seed_from_u64(seed);
13     let tx: Vec<Vec<char>> = iter::repeat_with(|| {
14         rng.sample_iter(&Alphanumeric)
15             .take(32)
16             .map(char::from)
17             .collect()
18     })
19     .take(4096)
20     .collect();
21 
22     // more readable with explicit `true` / `false`
23     #[allow(clippy::bool_assert_comparison)]
24     for _ in 0..32 {
25         for x in &tx {
26             assert_eq!(m.contains(x), false);
27             assert_eq!(m.insert(x.clone()), true);
28         }
29         for (i, x) in tx.iter().enumerate() {
30             println!("removing {} {:?}", i, x);
31             assert_eq!(m.remove(x), true);
32         }
33     }
34 }
35