Skip to content

Commit ae39957

Browse files
committed
Add extract_if_non_contiguous case
Signed-off-by: tison <[email protected]>
1 parent 425aefb commit ae39957

File tree

1 file changed

+22
-0
lines changed
  • library/alloc/src/collections/vec_deque

1 file changed

+22
-0
lines changed

library/alloc/src/collections/vec_deque/tests.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,28 @@ fn extract_if_true() {
12691269
assert_eq!(list, vec![]);
12701270
}
12711271

1272+
#[test]
1273+
fn extract_if_non_contiguous() {
1274+
let mut list =
1275+
[1, 2, 4, 6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, 39]
1276+
.into_iter()
1277+
.collect::<VecDeque<_>>();
1278+
list.rotate_left(3);
1279+
1280+
assert!(!list.is_contiguous());
1281+
assert_eq!(
1282+
list,
1283+
[6, 7, 9, 11, 13, 15, 17, 18, 20, 22, 24, 26, 27, 29, 31, 33, 34, 35, 36, 37, 39, 1, 2, 4]
1284+
);
1285+
1286+
let removed = list.extract_if(.., |x| *x % 2 == 0).collect::<Vec<_>>();
1287+
assert_eq!(removed.len(), 10);
1288+
assert_eq!(removed, vec![6, 18, 20, 22, 24, 26, 34, 36, 2, 4]);
1289+
1290+
assert_eq!(list.len(), 14);
1291+
assert_eq!(list, vec![7, 9, 11, 13, 15, 17, 27, 29, 31, 33, 35, 37, 39, 1]);
1292+
}
1293+
12721294
#[test]
12731295
fn extract_if_complex() {
12741296
{

0 commit comments

Comments
 (0)