about summary refs log tree commit diff
path: root/src/libcollectionstest/binary_heap.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcollectionstest/binary_heap.rs')
-rw-r--r--src/libcollectionstest/binary_heap.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libcollectionstest/binary_heap.rs b/src/libcollectionstest/binary_heap.rs
index 1df341d1fc2..a0846f57082 100644
--- a/src/libcollectionstest/binary_heap.rs
+++ b/src/libcollectionstest/binary_heap.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use std::panic;
 use std::collections::BinaryHeap;
 use std::collections::binary_heap::{Drain, PeekMut};
 
@@ -310,6 +311,26 @@ fn test_extend_specialization() {
     assert_eq!(a.into_sorted_vec(), [-20, -10, 1, 2, 3, 3, 5, 43]);
 }
 
+#[test]
+fn test_placement() {
+    let mut a = BinaryHeap::new();
+    a.place() <- 2;
+    a.place() <- 4;
+    a.place() <- 3;
+    assert_eq!(a.peek(), Some(&4));
+    assert_eq!(a.len(), 3);
+    a.place() <- 1;
+    assert_eq!(a.into_sorted_vec(), vec![1, 2, 3, 4]);
+}
+
+#[test]
+fn test_placement_panic() {
+    let mut heap = BinaryHeap::from(vec![1, 2, 3]);
+    fn mkpanic() -> usize { panic!() }
+    let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| { heap.place() <- mkpanic(); }));
+    assert_eq!(heap.len(), 3);
+}
+
 #[allow(dead_code)]
 fn assert_covariance() {
     fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> {