示例#1
0
def test_right_linked_list_four():
    tree = TreeNode(0)
    tree.insert(1)
    tree.insert(2)
    tree.insert(3)
    assert tree.balance() == -3
    tree = tree.rebalance(tree)
    assert tree.balance() == 1
示例#2
0
def test_left_linked_list():
    tree = TreeNode(2)
    tree.insert(1)
    tree.insert(0)
    assert tree.balance() == 2
    tree = tree.rebalance(tree)
    assert tree.balance() == 0
    treelist = [n for n in tree.depth_traversal("in")]
    assert treelist == [0, 1, 2]
示例#3
0
def test_balance():
    tree = TreeNode(5)
    assert tree.balance() == 0
    tree.insert(1)
    assert tree.balance() == 1
    tree.insert(6)
    assert tree.balance() == 0
    tree.insert(3)
    tree.insert(4)
    assert tree.balance() == 2
示例#4
0
def test_left_linked_list_four():
    tree = TreeNode(3)
    tree.insert(2)
    tree.insert(1)
    tree.insert(0)
    assert tree.balance() == 3
    assert tree.val == 3
    tree = tree.rebalance(tree)
    assert tree.balance() == -1
    assert tree.val == 1
示例#5
0
def test_complicated():
    tree = TreeNode(50)
    tree.insert(25)
    tree.insert(30)
    tree.insert(27)
    tree.insert(26)
    tree.insert(60)
    tree.insert(70)
    assert tree.balance() == 2
    tree = tree.rebalance(tree)
    assert tree.balance() == 1