def test_two_duplicate_strings(): binarytree1, binarytree2 = BinaryTreeSearch(), BinaryTreeSearch() binarytree1.root.value = "cat" binarytree1.root.right_node = Node("dog") binarytree1.root.left_node = Node("unicorn") binarytree1.root.value = "horse" binarytree1.root.right_node = Node("dog") binarytree1.root.left_node = Node("unicorn") binarytree1.root.left_node.left_node = Node("cat") actual = tree_intersection(binarytree1, binarytree2) expected = ["cat", "dog"] assert actual == expected
def test_same_abs_value(): binarytree1, binarytree2 = BinaryTreeSearch(), BinaryTreeSearch() binarytree1.add(3) binarytree1.add(5) binarytree1.add(31) binarytree1.add(-11) binarytree2.add(7) binarytree2.add(3) binarytree2.add(11) binarytree2.add(-31) actual = tree_intersection(binarytree1, binarytree2) expected = [3] assert actual == expected
def test_add_bigger_tree_up_high(): t = BinaryTreeSearch(5) t.add(9) t.add(4) t.add(7) t.add(6) t.add(3) actual = t.root.right_node.value expected = 9 assert actual == expected
def test_add_bigger_tree_down_low(): t = BinaryTreeSearch(5) t.add(9) t.add(4) t.add(7) t.add(6) t.add(3) actual = t.root.right_node.left_node.value expected = 7 assert actual == expected
def test_add_without_primer_value(): t = BinaryTreeSearch() t.add(5) t.add(9) t.add(4) t.add(7) t.add(6) t.add(3) actual = t.root.right_node.value expected = 9 assert actual == expected
def test_not_contains(): t = BinaryTreeSearch(5) t.add(9) t.add(7) t.add(6) t.add(3) actual = t.contains(10) expected = False assert actual == expected
def test_contains_at_top(): t = BinaryTreeSearch(5) t.add(9) t.add(7) t.add(6) t.add(3) actual = t.contains(5) expected = True assert actual == expected
def test_one_duplicate(): binarytree1, binarytree2 = BinaryTreeSearch(), BinaryTreeSearch() binarytree1.add(3) binarytree1.add(5) binarytree1.add(7) binarytree2.add(4) binarytree2.add(3) binarytree2.add(11) binarytree2.add(31) actual = tree_intersection(binarytree1, binarytree2) expected = [3] assert actual == expected
def test_two_negitive_duplicates(): binarytree1, binarytree2 = BinaryTreeSearch(), BinaryTreeSearch() binarytree1.add(3) binarytree1.add(5) binarytree1.add(-31) binarytree1.add(-11) binarytree2.add(7) binarytree2.add(3) binarytree2.add(-11) binarytree2.add(-31) actual = tree_intersection(binarytree1, binarytree2) expected = [-31, -11, 3] assert actual == expected
def test_preOrder(): t = BinaryTreeSearch() t.add(5) t.add(9) t.add(4) t.add(14) t.add(7) t.add(6) t.add(3) actual = t.preOrder() expected = [ 5, 4, 3, 9, 7, 6, 14, ] assert actual == expected
def test_add_left_child(): t = BinaryTreeSearch(7) t.add(5) actual = t.root.left_node.value expected = 5 assert actual == expected
def test_one_empty_tree(): binarytree1, binarytree2 = BinaryTree(), BinaryTreeSearch() binarytree2.add(3) actual = tree_intersection(binarytree1, binarytree2) expected = [] assert actual == expected
def test_postOrder(): t = BinaryTreeSearch() t.add(5) t.add(9) t.add(4) t.add(14) t.add(7) t.add(6) t.add(3) actual = t.postOrder() expected = [ 3, 4, 6, 7, 14, 9, 5, ] assert actual == expected
def test_postOrder_on_empty(): t = BinaryTreeSearch() actual = t.postOrder() expected = [None] assert actual == expected
def test_provided_example_test(): binarytree1, binarytree2 = BinaryTreeSearch(), BinaryTreeSearch() binarytree1.add(150) binarytree1.add(100) binarytree1.add(250) binarytree1.add(75) binarytree1.add(160) binarytree1.add(200) binarytree1.add(350) binarytree1.add(125) binarytree1.add(175) binarytree1.add(300) binarytree1.add(500) binarytree2.add(42) binarytree2.add(100) binarytree2.add(600) binarytree2.add(15) binarytree2.add(160) binarytree2.add(200) binarytree2.add(350) binarytree2.add(125) binarytree2.add(175) binarytree2.add(4) binarytree2.add(500) actual = tree_intersection(binarytree1, binarytree2) expected = [100, 125, 160, 175, 200, 350, 500] assert actual == expected
def test_find_max_in_non_bst_w_neg(): t = BinaryTreeSearch() t.add(5) t.add(9) t.add(4) t.add(22) t.add(7) t.add(6) t.add(-3) actual = t.find_maximum_value() expected = 22 assert actual == expected
def test_find_max_in_bst(): t = BinaryTreeSearch() t.add(5) t.add(9) t.add(4) t.add(14) t.add(7) t.add(6) t.add(3) actual = t.find_maximum_value() expected = 14 assert actual == expected
def test_find_max_in_non_bst_mid_branch(): t = BinaryTreeSearch() t.add(5) t.add(9) t.add(4) t.add(14) t.add(7) t.add(6) t.add(3) t.add(2) t.root.left_node.left_node.value = 18 t.add(4.5) t.root.left_node.right_node.value = 18 actual = t.find_maximum_value() expected = 18 assert actual == expected
def test_add_right_child(): t = BinaryTreeSearch(5) t.add(9) actual = t.root.right_node.value expected = 9 assert actual == expected
def test_find_max_in_bst_all_neg(): t = BinaryTreeSearch() t.add(-5) t.add(-9) t.add(-4) t.add(-14) t.add(-7) t.add(-6) t.add(-3) actual = t.find_maximum_value() expected = -3 assert actual == expected
def test_breadthOrder_empty(): t = BinaryTreeSearch() actual = t.breadthOrder() expected = [None] assert actual == expected
def test_breadthOrder(): t = BinaryTreeSearch() t.add(5) t.add(9) t.add(4) t.add(14) t.add(7) t.add(6) t.add(3) actual = t.breadthOrder() expected = [ 5, 4, 9, 3, 7, 14, 6, ] assert actual == expected