Skip to content

Commit

Permalink
test: assert that nodes have ref_count of 1 for one treap insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Dec 21, 2023
1 parent 0c6587e commit e9d939f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions mast/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions mast/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::assert_eq;

use crate::node::Node;
use crate::treap::HashTreap;
use crate::Hash;
Expand Down Expand Up @@ -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<_>>();

Expand Down

0 comments on commit e9d939f

Please sign in to comment.