From e9d939f017a8ec421f0a644a1266a55ec406cddb Mon Sep 17 00:00:00 2001 From: nazeh Date: Thu, 21 Dec 2023 21:50:56 +0300 Subject: [PATCH] test: assert that nodes have ref_count of 1 for one treap insertion --- mast/src/node.rs | 4 ++++ mast/src/test.rs | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mast/src/node.rs b/mast/src/node.rs index 00faa38..07c3aab 100644 --- a/mast/src/node.rs +++ b/mast/src/node.rs @@ -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 { diff --git a/mast/src/test.rs b/mast/src/test.rs index 64adae3..2fa7dd0 100644 --- a/mast/src/test.rs +++ b/mast/src/test.rs @@ -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::>();