From ebfce09c0e93c1ff96590e041bf3a9a0cd97a3fd Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Mon, 13 Jan 2025 22:11:05 +1300 Subject: [PATCH] Add (failing) (minimal) IndexedQueue (Rust) tests --- tests/indexed_binary_heap.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/indexed_binary_heap.rs diff --git a/tests/indexed_binary_heap.rs b/tests/indexed_binary_heap.rs new file mode 100644 index 0000000..c5af8e2 --- /dev/null +++ b/tests/indexed_binary_heap.rs @@ -0,0 +1,30 @@ +#[cfg(test)] +mod tests { + use pyority_queue::backing::indexed::{IndexedBacking, IndexedBinaryHeap}; + + #[test] + fn test_indexed_binary_heap_manual_creation() { + let mut heap = IndexedBinaryHeap::new(); + heap.set(4, 0.5); + heap.set(-3, 0.01); + heap.set(6, 0.9); + heap.set(1, 0.2); + assert_eq!(heap.len(), 4); + assert_eq!(heap.pop(), Some(-3)); + assert_eq!(heap.pop(), Some(1)); + assert_eq!(heap.pop(), Some(4)); + assert_eq!(heap.pop(), Some(6)); + assert_eq!(heap.pop(), None); + } + + #[test] + fn test_indexed_binary_heap_from_iter() { + let mut heap = IndexedBinaryHeap::from_iter(vec![("c", 7), ("a", 3), ("b", 6), ("d", 9)]); + assert_eq!(heap.len(), 4); + assert_eq!(heap.pop(), Some("a")); + assert_eq!(heap.pop(), Some("b")); + assert_eq!(heap.pop(), Some("c")); + assert_eq!(heap.pop(), Some("d")); + assert_eq!(heap.pop(), None); + } +}