diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2020-11-02 20:40:12 +0100 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2021-04-22 14:24:30 +0200 |
| commit | f5d72ab69b997a62dc5c240de1a180b8a96daf71 (patch) | |
| tree | 0ff587c8b6164e3c243237fb9dcf459df958d207 | |
| parent | 62226eecb6a287b5e0ba360e54349cca7afbf0bc (diff) | |
| download | rust-f5d72ab69b997a62dc5c240de1a180b8a96daf71.tar.gz rust-f5d72ab69b997a62dc5c240de1a180b8a96daf71.zip | |
Add better test for BinaryHeap::retain.
| -rw-r--r-- | library/alloc/tests/binary_heap.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/library/alloc/tests/binary_heap.rs b/library/alloc/tests/binary_heap.rs index ce794a9a4af..a7913dcd287 100644 --- a/library/alloc/tests/binary_heap.rs +++ b/library/alloc/tests/binary_heap.rs @@ -386,10 +386,23 @@ fn assert_covariance() { #[test] fn test_retain() { - let mut a = BinaryHeap::from(vec![-10, -5, 1, 2, 4, 13]); - a.retain(|x| x % 2 == 0); + let mut a = BinaryHeap::from(vec![100, 10, 50, 1, 2, 20, 30]); + a.retain(|&x| x != 2); - assert_eq!(a.into_sorted_vec(), [-10, 2, 4]) + // Check that 20 moved into 10's place. + assert_eq!(a.clone().into_vec(), [100, 20, 50, 1, 10, 30]); + + a.retain(|_| true); + + assert_eq!(a.clone().into_vec(), [100, 20, 50, 1, 10, 30]); + + a.retain(|&x| x < 50); + + assert_eq!(a.clone().into_vec(), [30, 20, 10, 1]); + + a.retain(|_| false); + + assert!(a.is_empty()); } // old binaryheap failed this test |
