From 1d4b3f8e57fa97854fd06b6e469a2626b54be441 Mon Sep 17 00:00:00 2001 From: azizkayumov Date: Sun, 12 Nov 2023 03:43:26 +0900 Subject: [PATCH] fix tests --- src/splay.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/splay.rs b/src/splay.rs index d9cc946..216c229 100644 --- a/src/splay.rs +++ b/src/splay.rs @@ -321,6 +321,17 @@ mod tests { forest.cut_left(bob); } + #[test] + #[should_panic] + pub fn rotate_left_invalid() { + let mut forest: Forest = super::Forest::new(); + let alice = forest.create_node(0.0); + let bob = forest.create_node(0.0); + forest.set_left(alice, bob); + // Should panic because alice does not have a right child + forest.rotate_left(alice); + } + #[test] pub fn rotate_left_root() { // form the following tree and rotate left on 'a': @@ -359,6 +370,17 @@ mod tests { assert!(forest.right_of(e).is_none()); } + #[test] + #[should_panic] + pub fn rotate_right_invalid() { + let mut forest: Forest = super::Forest::new(); + let alice = forest.create_node(0.0); + let bob = forest.create_node(0.0); + forest.set_right(alice, bob); + // Should panic because alice does not have a left child + forest.rotate_right(alice); + } + #[test] pub fn rotate_right_root() { // form the tree and rotate right on 'a': @@ -397,6 +419,17 @@ mod tests { assert!(forest.right_of(e).is_none()); } + #[test] + #[should_panic] + pub fn rotate_invalid() { + let mut forest: Forest = super::Forest::new(); + let alice = forest.create_node(0.0); + let bob = forest.create_node(0.0); + forest.set_left(alice, bob); + // Should panic because alice does not have a parent + forest.rotate(alice); + } + #[test] pub fn rotate_parent_left() { // form the tree and rotate on '1':