Skip to content

Commit 6328647

Browse files
authored
Merge pull request #347 from cuviper/test-erase_indices
Test the various heuristics of `erase_indices`
2 parents abdd155 + efa81da commit 6328647

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/map/tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,26 @@ fn into_values() {
541541
assert!(values.contains(&'c'));
542542
}
543543

544+
#[test]
545+
fn drain_range() {
546+
// Test the various heuristics of `erase_indices`
547+
for range in [
548+
0..0, // nothing erased
549+
10..90, // reinsert the few kept (..10 and 90..)
550+
80..90, // update the few to adjust (80..)
551+
20..30, // sweep everything
552+
] {
553+
let mut vec = Vec::from_iter(0..100);
554+
let mut map: IndexMap<i32, ()> = (0..100).map(|i| (i, ())).collect();
555+
drop(vec.drain(range.clone()));
556+
drop(map.drain(range));
557+
assert!(vec.iter().eq(map.keys()));
558+
for (i, x) in vec.iter().enumerate() {
559+
assert_eq!(map.get_index_of(x), Some(i));
560+
}
561+
}
562+
}
563+
544564
#[test]
545565
#[cfg(feature = "std")]
546566
fn from_array() {

0 commit comments

Comments
 (0)