diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 1428f89..8daa36d 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -1,4 +1,4 @@ -name: coverage +name: Coverage on: push: diff --git a/src/lctree.rs b/src/lctree.rs index 3c8301a..e984689 100644 --- a/src/lctree.rs +++ b/src/lctree.rs @@ -559,4 +559,22 @@ mod tests { assert_eq!(lctree.path(4, 3).sum, 15.); assert_eq!(lctree.path(5, 7).sum, 9.); } + + #[test] + pub fn test_extend_forest() { + let weights = vec![1.0, 2.0, 3.0]; + let mut lctree = LinkCutTree::default(); + let trees_ids = lctree.extend_forest(&weights); + assert_eq!(trees_ids, vec![0, 1, 2]); + } + + #[test] + #[should_panic] + pub fn delete_tree() { + let mut lctree = LinkCutTree::default(); + let alice = lctree.make_tree(0.0); + let bob = lctree.make_tree(1.0); + lctree.link(alice, bob); + lctree.remove_tree(alice); // should panic + } } diff --git a/src/node.rs b/src/node.rs index 1ac6e48..7c27ebc 100644 --- a/src/node.rs +++ b/src/node.rs @@ -39,7 +39,7 @@ impl Node { } #[allow(dead_code)] - #[cfg_attr(tarpaulin, ignore)] + #[cfg(not(tarpaulin_include))] pub fn to_str(&self) -> String { let parent = match self.parent { Parent::Node(idx) => format!("Node({idx})"), diff --git a/src/splay.rs b/src/splay.rs index 7e3b377..6aa72a3 100644 --- a/src/splay.rs +++ b/src/splay.rs @@ -280,6 +280,55 @@ mod tests { forest } + #[test] + pub fn create_node() { + let mut forest: Forest = super::Forest::new(); + let alice = forest.create_node(0.0); + let bob = forest.create_node(1.0); + let charlie = forest.create_node(2.0); + assert_eq!([alice, bob, charlie], [0, 1, 2]); + + forest.delete_node(bob); + let david = forest.create_node(4.0); + // Should reuse the space of bob's tree (which was removed) + assert_eq!(david, bob); + } + + #[test] + #[should_panic] + pub fn set_right() { + let mut forest: Forest = super::Forest::new(); + let alice = forest.create_node(0.0); + let bob = forest.create_node(1.0); + forest.set_right(alice, bob); + let charlie = forest.create_node(2.0); + // Should panic because alice already has a right child + forest.set_right(alice, charlie); + } + + #[test] + #[should_panic] + pub fn set_left() { + let mut forest: Forest = super::Forest::new(); + let alice = forest.create_node(0.0); + let bob = forest.create_node(1.0); + forest.set_left(alice, bob); + let charlie = forest.create_node(2.0); + // Should panic because alice already has a left child + forest.set_left(alice, charlie); + } + + #[test] + #[should_panic] + pub fn cut_left() { + let mut forest: Forest = super::Forest::new(); + let alice = forest.create_node(0.0); + let bob = forest.create_node(1.0); + forest.set_left(alice, bob); + // Should panic because alice does not have a left child + forest.cut_left(bob); + } + #[test] pub fn rotate_left_root() { // form the following tree and rotate left on '0':