Exemple #1
0
def test_tree_add_children_to_single_root():
    expected = [2, 5, 6]
    node = Node(5)
    node.left = Node(2)
    node.right = Node(6)
    btt = BinaryTree(node)
    actual = btt.inOrder()
    assert actual == expected
def test_can_successfully_return_a_collection_from_an_inorder_traversal():
    new_tree = BinaryTree()
    new_tree.root = Node("A")
    new_tree.root.left = Node("B")
    new_tree.root.right = Node("C")
    new_tree.root.right.left = Node("F") 
    new_tree.root.left.left = Node("D")       
    new_tree.root.left.right = Node("E")       
    expected = ["D", "B", "E", "A", "F", "C"]
    actual = new_tree.inOrder()
    assert expected == actual
def test_5 ():
    node1 = TNode(1)
    node1.left = TNode(2)
    node1.right = TNode(3)
    node1.right.left = TNode(5)
    node1.right.right = TNode(4)
    node1.left.right = TNode(6)
    node1.left.left = TNode(7)
    binary_tree = BinaryTree(node1)


    actual = binary_tree.inOrder().__str__()
    expected = '-> 4 -> 3 -> 5 -> 1 -> 6 -> 2 -> 7 -> None'
    assert actual == expected