def test_can_successfully_add_a_left_child_and_right_child_to_a_single_root_node(): new_tree = BinaryTree() new_tree.root = Node(1) new_tree.root.left = Node(2) new_tree.root.right = Node(3) expected = [1, 2, 3] actual = new_tree.preOrder() assert expected == actual
def test_can_successfully_return_a_collection_from_a_preorder_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 = ["A", "B", "D", "E", "C", "F"] actual = new_tree.preOrder() assert expected == actual
def test_4 (): 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.preOrder().__str__() expected = '-> 4 -> 5 -> 3 -> 6 -> 7 -> 2 -> 1 -> None' assert actual == expected
def test_instantiate_an_empty_tree(): expected = [] btt = BinaryTree() actual = btt.preOrder() assert actual == expected
def test_instantiate_tree_with_single_root(): expected = [5] node = Node(5) btt = BinaryTree(node) actual = btt.preOrder() assert actual == expected