def testt_left_right_rotation_five_node_tree(): """Test three nodes rotate right, no root change.""" from bbst import Bst tree = Bst([4, 5, 1, 3, 2]) assert tuple(tree.in_order()) == (1, 2, 3, 4, 5) assert tuple(tree.breadth_first()) == (4, 2, 5, 1, 3) assert tuple(tree.pre_order()) == (4, 2, 1, 3, 5) assert tuple(tree.post_order()) == (1, 3, 2, 5, 4) assert tree.depth() == 3 assert tree.balance() == -1
def test_left_rotation_three_node_tree_including_root(): """Test three nodes rotate right.""" from bbst import Bst tree = Bst([3, 4, 5]) assert tuple(tree.in_order()) == (3, 4, 5) assert tuple(tree.breadth_first()) == (4, 3, 5) assert tuple(tree.pre_order()) == (4, 3, 5) assert tuple(tree.post_order()) == (3, 5, 4) assert tree.depth() == 2 assert tree.balance() == 0
def test_left_rotation_four_node_tree(): """Test four nodes rotate left, no root change.""" from bbst import Bst tree = Bst([1, 2, 3, 4, 5]) assert tuple(tree.in_order()) == (1, 2, 3, 4, 5) assert tuple(tree.breadth_first()) == (2, 1, 4, 3, 5) assert tuple(tree.pre_order()) == (2, 1, 4, 3, 5) assert tuple(tree.post_order()) == (1, 3, 5, 4, 2) assert tree.depth() == 3 assert tree.balance() == 1
def test_rand_100_depth_remains_less_than_8(): """Test 100 numbers depth rational.""" from bbst import Bst from random import shuffle max_depth = 0 for x in range(10): rando = [x for x in range(100)] shuffle(rando) tree = Bst(rando) tree_depth = tree.depth() if tree_depth > max_depth: max_depth = tree_depth assert max_depth == 8