Пример #1
0
def FizzBuzzTree(tree):
    """
    k-ary : can have any number of nodes
    """
    if tree.root != None:
        pass

    else:
        tree.root =Node('Tree is Empty')
        return tree
Пример #2
0
def test_print_breadth_first_traversal(mock_print):
    tree = BinaryTree("1")
    tree.root.left = Node("2")
    tree.root.right = Node("3")
    tree.root.left.left = Node("4")
    tree.root.left.right = Node("5")
    tree.root.right.left = Node("6")
    tree.root.right.right = Node("7")
    tree.root.right.right = Node("8")
    print(tree.breadth_first_traversal())
    mock_print.assert_called_once_with([1, 2, 3, 4, 5, 6, 8])
Пример #3
0
def test_print_maximum_value(mock_print):
    tree = BinaryTree("1")
    tree.root.left = Node("2")
    tree.root.right = Node("3")
    tree.root.left.left = Node("4")
    tree.root.left.right = Node("5")
    tree.root.right.left = Node("6")
    tree.root.right.right = Node("7")
    tree.root.right.right = Node("8")
    print(tree.find_maximum_value(tree.print_tree("preOrder")))
    mock_print.assert_called_once_with(8)
Пример #4
0
def test_print_preOrder(mock_print):
    tree = BinaryTree("1")
    tree.root.left = Node("2")
    tree.root.right = Node("3")
    tree.root.left.left = Node("4")
    tree.root.left.right = Node("5")
    tree.root.right.left = Node("6")
    tree.root.right.right = Node("7")
    print(tree.print_tree("preOrder"))
    mock_print.assert_called_once_with(['1', '2', '4', '5', '3', '6', '8'])
Пример #5
0
def test_add_right_child():
    tree = BinaryTree(1)
    tree.root.right = Node(3)
    assert tree.root.right.value == 3
Пример #6
0
def test_add_left_child():
    tree = BinaryTree(1)
    tree.root.left = Node(2)
    assert tree.root.left.value == 2