Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
azizkayumov committed Nov 11, 2023
1 parent 52a4d56 commit 1d4b3f8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/splay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ mod tests {
forest.cut_left(bob);
}

#[test]
#[should_panic]
pub fn rotate_left_invalid() {
let mut forest: Forest<FindMax> = 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':
Expand Down Expand Up @@ -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<FindMax> = 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':
Expand Down Expand Up @@ -397,6 +419,17 @@ mod tests {
assert!(forest.right_of(e).is_none());
}

#[test]
#[should_panic]
pub fn rotate_invalid() {
let mut forest: Forest<FindMax> = 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':
Expand Down

0 comments on commit 1d4b3f8

Please sign in to comment.