Add rough binary heap test

This commit is contained in:
Michael Bradley 2025-01-04 00:16:08 +13:00
parent df7536b82b
commit b273772722
Signed by: MichaelBradley
SSH key fingerprint: SHA256:cj/YZ5VT+QOKncqSkx+ibKTIn0Obg7OIzwzl9BL8EO8
2 changed files with 29 additions and 1 deletions

View file

@ -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"

28
tests/pure_binary_heap.rs Normal file
View file

@ -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);
}
}