From b273772722c9781152b86c9397b29cf68c0294aa Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Sat, 4 Jan 2025 00:16:08 +1300 Subject: [PATCH] Add rough binary heap test --- Cargo.toml | 2 +- tests/pure_binary_heap.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/pure_binary_heap.rs diff --git a/Cargo.toml b/Cargo.toml index d440b58..0da9dff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] name = "pyority_queue" -crate-type = ["cdylib"] +crate-type = ["cdylib", "rlib"] [dependencies] pyo3 = "0.23.3" diff --git a/tests/pure_binary_heap.rs b/tests/pure_binary_heap.rs new file mode 100644 index 0000000..a6326c2 --- /dev/null +++ b/tests/pure_binary_heap.rs @@ -0,0 +1,28 @@ +#[cfg(test)] +mod tests { + use pyority_queue::backing::pure::{binary_heap::BinaryHeap, PureBacking}; + + #[test] + fn test_pure_binary_heap() { + let mut heap = BinaryHeap::new(); + assert_eq!(heap.len(), 0); + heap.add(4); + assert_eq!(heap.len(), 1); + heap.add(-3); + assert_eq!(heap.len(), 2); + heap.add(6); + assert_eq!(heap.len(), 3); + heap.add(1); + assert_eq!(heap.len(), 4); + assert_eq!(heap.pop(), Some(-3)); + assert_eq!(heap.len(), 3); + assert_eq!(heap.pop(), Some(1)); + assert_eq!(heap.len(), 2); + assert_eq!(heap.pop(), Some(4)); + assert_eq!(heap.len(), 1); + assert_eq!(heap.pop(), Some(6)); + assert_eq!(heap.len(), 0); + assert_eq!(heap.pop(), None); + assert_eq!(heap.len(), 0); + } +}