Пример #1
0
def test_print_tree(capsys):
    root = Node(30)
    root.insert(5)
    root.insert(15)
    root.insert(2)

    root.print_tree()
    out, err = capsys.readouterr()
    assert out == "2 5 15 30 "
Пример #2
0
def test_dfs():

    ary = [10, 9, 55, 25, 75, 5, 60, 30, 100]
    root = Node(50)
    for x in ary:
        root.insert(x)
    #         50
    #     10      55
    #   9    25      75
    # 5       30   60   100

    tree = Tree(root)
    assert tree.generate_list() == [50, 10, 9, 5, 25, 30, 55, 75, 60, 100]
Пример #3
0
def test_insert_left_node_recursive():
    root_node = Node(20)
    assert root_node.data == 20
    root_node.insert(10)
    assert root_node.left.data == 10
    root_node.insert(5)
    assert root_node.left.left.data == 5
Пример #4
0
def test_insert_right_node_recursive():
    root_node = Node(5)
    assert root_node.data == 5
    root_node.insert(10)
    assert root_node.right.data == 10
    root_node.insert(20)
    assert root_node.right.right.data == 20
Пример #5
0
def test_tree(capsys):
    ary = [10, 9, 55, 25, 75, 5, 30, 100]
    root = Node(50)
    for x in ary:
        root.insert(x)

    #         50
    #     10      55
    #   9    25       75
    # 5       30        100

    root.print_tree()
    out, err = capsys.readouterr()
    assert out == "5 9 10 25 30 50 55 75 100 "
Пример #6
0
def test_node(capsys):
    n = Node(5)
    n.print()
    out, err = capsys.readouterr()
    assert out == "5 "
Пример #7
0
def test_insert_node_value():
    n = Node(5)
    n.insert(10)
    assert n.data == 5
    assert n.left == None
    assert n.right.data == 10
Пример #8
0
def test_insert_node_null():
    n = Node(5)
    n.insert(None)
    assert n.data == None