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_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_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_backwards_100_balance_remains_between_1_and_negative_1(): """Test 100 numbers in a row still has balance.""" from bbst import Bst tree = Bst([x for x in range(100)][::-1]) assert tree.balance() in range(-1, 2)
def test_straight_100_balance_remains_between_1and_negative_1(): """Test 100 numbers in a row still has balance.""" from bbst import Bst tree = Bst(x for x in range(100)) assert tree.balance() in range(-1, 2)