Skip to content

Commit

Permalink
Merge pull request #347 from cuviper/test-erase_indices
Browse files Browse the repository at this point in the history
Test the various heuristics of `erase_indices`
  • Loading branch information
cuviper authored Sep 13, 2024
2 parents abdd155 + efa81da commit 6328647
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,26 @@ fn into_values() {
assert!(values.contains(&'c'));
}

#[test]
fn drain_range() {
// Test the various heuristics of `erase_indices`
for range in [
0..0, // nothing erased
10..90, // reinsert the few kept (..10 and 90..)
80..90, // update the few to adjust (80..)
20..30, // sweep everything
] {
let mut vec = Vec::from_iter(0..100);
let mut map: IndexMap<i32, ()> = (0..100).map(|i| (i, ())).collect();
drop(vec.drain(range.clone()));
drop(map.drain(range));
assert!(vec.iter().eq(map.keys()));
for (i, x) in vec.iter().enumerate() {
assert_eq!(map.get_index_of(x), Some(i));
}
}
}

#[test]
#[cfg(feature = "std")]
fn from_array() {
Expand Down

0 comments on commit 6328647

Please sign in to comment.