def test_breadth():
    bt = BinaryTree()
    bst = BinarySearchTree()
    bt.add(4)
    bt.add(7)
    bt.add(5)
    bt.add(9)
    bt.add(2)
    bt.add(30)
    bt.add(-1)
    actual = bt.breadth_first()
    expected = [4, 7, 5, 9, 2, 30, -1]
    assert actual == expected
Exemplo n.º 2
0
def test_find_max():
    tree = BinaryTree()
    tree.add(10)
    tree.add(5)
    tree.add(15)
    tree.add(7)
    tree.add(3)
    tree.add(12)
    tree.add(6)
    tree.add(18)

    expected = [10, 5, 15, 3, 7, 12, 18, 6]
    actual = BinaryTree.find_maximum_value(tree)
    assert expected == actual
Exemplo n.º 3
0
def default_tree():
    xmas = BinaryTree(Node(35))
    xmas.add(20)
    xmas.add(60)
    xmas.add(10)
    xmas.add(24)
    xmas.add(2)
    xmas.add(18)
    xmas.add(22)
    xmas.add(28)
    xmas.add(45)
    xmas.add(90)
    xmas.add(43)
    xmas.add(55)
    xmas.add(77)
    xmas.add(99)
    #           35
    #     20          60
    #  10    24    45    90
    # 2 18  22 28 43 55 77 99
    return xmas
Exemplo n.º 4
0
def test_root_children():
    xmas = BinaryTree(Node(35))
    xmas.add(20)
    xmas.add(60)
    assert xmas.head.left and xmas.head.right