Skip to content

Commit f5d72ab

Browse files
committed
Add better test for BinaryHeap::retain.
1 parent 62226ee commit f5d72ab

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

library/alloc/tests/binary_heap.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,23 @@ fn assert_covariance() {
386386

387387
#[test]
388388
fn test_retain() {
389-
let mut a = BinaryHeap::from(vec![-10, -5, 1, 2, 4, 13]);
390-
a.retain(|x| x % 2 == 0);
389+
let mut a = BinaryHeap::from(vec![100, 10, 50, 1, 2, 20, 30]);
390+
a.retain(|&x| x != 2);
391391

392-
assert_eq!(a.into_sorted_vec(), [-10, 2, 4])
392+
// Check that 20 moved into 10's place.
393+
assert_eq!(a.clone().into_vec(), [100, 20, 50, 1, 10, 30]);
394+
395+
a.retain(|_| true);
396+
397+
assert_eq!(a.clone().into_vec(), [100, 20, 50, 1, 10, 30]);
398+
399+
a.retain(|&x| x < 50);
400+
401+
assert_eq!(a.clone().into_vec(), [30, 20, 10, 1]);
402+
403+
a.retain(|_| false);
404+
405+
assert!(a.is_empty());
393406
}
394407

395408
// old binaryheap failed this test

0 commit comments

Comments
 (0)