def test_tree_two(): tree = BinaryTree() one = Node(42) two = Node(100) three = Node(600) four = Node(15) five = Node(160) six = Node(200) seven = Node(350) eight = Node(125) nine = Node(175) ten = Node(4) eleven = Node(500) tree.root = one one.left = two one.right = three two.left = four two.right = five three.left = six three.right = seven five.left = eight five.right = nine seven.left = ten seven.right = eleven return tree
def test_bst(): bst = BinarySearchTree() one = Node(15) two = Node(12) three = Node(25) four = Node(24) five = Node(29) six = Node(36) bst.root = one one.left = two one.right = three three.left = four three.right = five five.right = six return bst
def test_tree(): tree = BinaryTree() one = Node(1) two = Node(2) three = Node(3) four = Node(4) five = Node(5) six = Node(6) tree.root = one one.left = two one.right = three two.left = four two.right = five three.left = six return tree
def test_assign_left_right(): groot = Node('Groot') eye = Node('I') am = Node('Am') groot.left = eye groot.right = am assert groot.left.value == 'I' assert groot.right.value == 'Am'
def test_breadth_first_even(): tree = BinaryTree() a = Node('A') b = Node('B') c = Node('C') d = Node('D') e = Node('E') f = Node('F') tree.root = a a.left = b a.right = c b.left = d b.right = e c.left = f actual = tree.breadth_first() expected = ['A', 'B', 'C', 'D', 'E', 'F'] assert actual == expected
def test_add_left_and_right(): tree = BinaryTree() node1 = Node(1) node2 = Node(3) node3 = Node(5) node1.left = node2 node1.right = node3 tree.root = node1 assert node1.left.value == 3 and node1.right.value == 5
def test_left_right_child_tree(): tree = BinaryTree() one = Node(25) two = Node(12) three = Node(30) tree.root = one one.left = two one.right = three assert one.left and one.right expected = two and three
def test_return_breadth_list(): tree = BinaryTree() node1 = Node(1) node2 = Node(9) node3 = Node(5) node1.left = node2 node1.right = node3 tree.root = node1 actual = tree.breadth_first() expected = [1, 9, 5] assert actual == expected
def test_return_desired_value(): tree = BinaryTree() node1 = Node(1) node2 = Node(3) node3 = Node(5) node1.left = node2 node1.right = node3 tree.root = node1 actual = tree.find_max_value() expected = 5 assert actual == expected
def test_postorder_traversal(): tree = BinaryTree() node1 = Node(1) node2 = Node(3) node3 = Node(5) node1.left = node2 node1.right = node3 tree.root = node1 actual = tree.post_order() expected = [3, 5, 1] assert actual == expected
def test_bst_contains_false(): hal = BinarySearchTree() jarvis = Node(9) mr_robot = Node(3) dva = Node(4) navi = Node(5) gdi = Node(7) nod = Node(2) ghost = Node(6) winter = Node(1) navi.left = nod navi.right = gdi nod.left = winter nod.right = dva dva.left = mr_robot gdi.left = ghost gdi.right = jarvis hal.root = navi actual = hal.contains(8) assert actual == False