test: assert that nodes have ref_count of 1 for one treap insertion

This commit is contained in:
nazeh
2023-12-21 21:50:56 +03:00
parent 0c6587e51f
commit e9d939f017
2 changed files with 13 additions and 3 deletions

View File

@@ -100,6 +100,10 @@ impl Node {
&self.right
}
pub(crate) fn ref_count(&self) -> &u64 {
&self.ref_count
}
// === Public Methods ===
pub fn rank(&self) -> Hash {

View File

@@ -1,3 +1,5 @@
use std::assert_eq;
use crate::node::Node;
use crate::treap::HashTreap;
use crate::Hash;
@@ -192,9 +194,13 @@ fn test(name: &str, input: &[(Entry, Operation)], expected: &[Entry], root_hash:
let collected = treap
.iter()
.map(|n| Entry {
key: n.key().to_vec(),
value: n.value().to_vec(),
.map(|n| {
assert_eq!(*n.ref_count(), 1_u64, "Node has wrong ref count");
Entry {
key: n.key().to_vec(),
value: n.value().to_vec(),
}
})
.collect::<Vec<_>>();