Debian Codegraph @

debian/rust-vendor/hashbrown/tests/set.rs

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