Skip to content

Commit acf95ad

Browse files
committedNov 26, 2022
Add second test case in make_contiguous_head_to_end
1 parent 4512598 commit acf95ad

File tree

1 file changed

+49
-10
lines changed
  • library/alloc/src/collections/vec_deque

1 file changed

+49
-10
lines changed
 

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

+49-10
Original file line numberDiff line numberDiff line change
@@ -549,16 +549,55 @@ fn make_contiguous_small_free() {
549549

550550
#[test]
551551
fn make_contiguous_head_to_end() {
552-
let mut dq = VecDeque::with_capacity(3);
553-
dq.push_front('B');
554-
dq.push_front('A');
555-
dq.push_back('C');
556-
dq.make_contiguous();
557-
let expected_head = 0;
558-
let expected_len = 3;
559-
assert_eq!(expected_head, dq.head);
560-
assert_eq!(expected_len, dq.len);
561-
assert_eq!((&['A', 'B', 'C'] as &[_], &[] as &[_]), dq.as_slices());
552+
let mut tester = VecDeque::with_capacity(16);
553+
554+
for i in b'A'..b'L' {
555+
tester.push_back(i as char);
556+
}
557+
558+
for i in b'L'..b'Q' {
559+
tester.push_front(i as char);
560+
}
561+
562+
assert_eq!(
563+
tester,
564+
['P', 'O', 'N', 'M', 'L', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
565+
);
566+
567+
// ABCDEFGHIJKPONML
568+
let expected_start = 0;
569+
tester.make_contiguous();
570+
assert_eq!(tester.head, expected_start);
571+
assert_eq!(
572+
(
573+
&['P', 'O', 'N', 'M', 'L', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
574+
as &[_],
575+
&[] as &[_]
576+
),
577+
tester.as_slices()
578+
);
579+
580+
tester.clear();
581+
for i in b'L'..b'Q' {
582+
tester.push_back(i as char);
583+
}
584+
585+
for i in b'A'..b'L' {
586+
tester.push_front(i as char);
587+
}
588+
589+
// LMNOPKJIHGFEDCBA
590+
let expected_start = 0;
591+
tester.make_contiguous();
592+
assert_eq!(tester.head, expected_start);
593+
assert_eq!(
594+
(
595+
&['K', 'J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A', 'L', 'M', 'N', 'O', 'P']
596+
as &[_],
597+
&[] as &[_]
598+
),
599+
tester.as_slices()
600+
);
562601
}
563602

564603
#[test]

0 commit comments

Comments
 (0)
Please sign in to comment.