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':