예제 #1
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
예제 #2
0
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
예제 #3
0
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