Skip to content

Commit 736223d

Browse files
committed
Unit test for Range parameter of BTreeMap::extract_if
1 parent 2b03f05 commit 736223d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

alloc/src/collections/btree/map/tests.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,30 @@ mod test_extract_if {
968968
map.check();
969969
}
970970

971+
#[test]
972+
fn consumed_removing_some() {
973+
let pairs = (0..3).map(|i| (i, i));
974+
let map = BTreeMap::from_iter(pairs);
975+
for x in 0..3 {
976+
for y in 0..3 {
977+
let mut map = map.clone();
978+
assert!(map.extract_if(x..y, |_, _| true).eq((x..y).map(|i| (i, i))));
979+
for i in 0..3 {
980+
assert_ne!(map.contains_key(&i), (x..y).contains(&i));
981+
}
982+
}
983+
}
984+
for x in 0..3 {
985+
for y in 0..2 {
986+
let mut map = map.clone();
987+
assert!(map.extract_if(x..=y, |_, _| true).eq((x..=y).map(|i| (i, i))));
988+
for i in 0..3 {
989+
assert_ne!(map.contains_key(&i), (x..=y).contains(&i));
990+
}
991+
}
992+
}
993+
}
994+
971995
// Explicitly consumes the iterator and modifies values through it.
972996
#[test]
973997
fn mutating_and_keeping() {

0 commit comments

Comments
 (0)