def test_intersect3(): tree1 = BinaryTree() tree2 = BinaryTree() tree1.add(-4) tree1.add(-5) tree1.add(-7) tree2.add(-7) expected = -7 actual = tree_matcher(tree1, tree2) assert actual == expected
def test_intersect1(): tree1 = BinaryTree() tree2 = BinaryTree() tree1.add(4) tree1.add(5) tree1.add(7) tree2.add(7) expected = 7 actual = tree_matcher(tree1, tree2) assert actual == expected
def test_empty_tree(): tree_one = BinaryTree() tree_one.add(12) tree_one.add(5) tree_one.add(3) tree_one.add(15) tree_two = BinaryTree() assert tree_intersection(tree_one, tree_two) == []
def test_empty_tree(): tree_1 = BinaryTree() tree_2 = BinaryTree() tree_2.add(12) tree_2.add(14) tree_2.add(5) expected = [] actual = tree_intersection(tree_1, tree_2) assert actual == expected
def test_tree_intersection(values_a, values_b, expected): """ The intersection of two trees is found. """ # Write add method for BinaryTree tree_a = BinaryTree() if len(values_a) == 6: tree_a.root = Node(values_a[0]) tree_a.root.left = Node(values_a[1]) tree_a.root.right = Node(values_a[2]) tree_a.root.left.left = Node(values_a[3]) tree_a.root.left.right = Node(values_a[4]) tree_a.root.right.right = Node(values_a[5]) # Write add method for BinaryTree tree_b = BinaryTree() if len(values_b) == 6: tree_b.root = Node(values_b[0]) tree_b.root.left = Node(values_b[1]) tree_b.root.right = Node(values_b[2]) tree_b.root.left.left = Node(values_b[3]) tree_b.root.left.right = Node(values_b[4]) tree_b.root.right.right = Node(values_b[5]) actual = tree_intersection(tree_a, tree_b) assert actual == expected
def test_binary_tree(): tree_one = BinaryTree() tree_one.add(12) tree_one.add(5) tree_one.add(3) tree_one.add(15) tree_two = BinaryTree() tree_two.add(1) tree_two.add(5) tree_two.add(12) tree_two.add(55) assert tree_one._root.value == 12 assert tree_two._root.value == 1 assert tree_one._root.left.value == 5
def test_tree_intersection(): tree_1 = BinaryTree() tree_1.add(15) tree_1.add(12) tree_1.add(8) tree_1.add(5) tree_2 = BinaryTree() tree_2.add(12) tree_2.add(14) tree_2.add(5) tree_2.add(2) expected = [5, 12] actual = tree_intersection(tree_1, tree_2) assert actual == expected
def test_tree_instance(): tree = BinaryTree() assert tree._root is None
def test_inner_contained_tree(): tree_one = BinaryTree() tree_one.add(55) tree_one.add(12) tree_one.add(6) tree_one.add(5) tree_one.add(3) tree_one.add(100) tree_one.add(23) tree_one.add(1) tree_two = BinaryTree() tree_two.add(12) tree_two.add(5) tree_two.add(3) assert tree_intersection(tree_one, tree_two) == [5, 3, 12]
def test_everything_matches(): tree_one = BinaryTree() tree_one.add(12) tree_one.add(5) tree_one.add(3) tree_one.add(15) tree_two = BinaryTree() tree_two.add(12) tree_two.add(5) tree_two.add(3) tree_two.add(15) assert tree_intersection(tree_one, tree_two) == [15, 5, 3, 12]
def test_multiple_matching_values_in_one_tree(): tree_one = BinaryTree() tree_one.add(4) tree_one.add(4) tree_one.add(4) tree_one.add(4) tree_two = BinaryTree() tree_two.add(12) tree_two.add(5) tree_two.add(3) tree_two.add(15) assert tree_intersection(tree_one, tree_two) == []
def test_tree_intersection(): tree_one = BinaryTree() tree_one.add(12) tree_one.add(5) tree_one.add(3) tree_one.add(15) tree_two = BinaryTree() tree_two.add(1) tree_two.add(5) tree_two.add(12) tree_two.add(55) assert tree_intersection(tree_one, tree_two) == [5, 12]