def test_return_all_common_values_from_both_trees(): """ Returns all common values from both trees """ t1 = BinaryTree() t2 = BinaryTree() t1_list = [2, 6, 1, 5, 10, 9, 3, 2] t2_list = [22, 4, 6, 5, 9] for num in t1_list: t1.breadth_add(num) for num in t2_list: t2.breadth_add(num) actual = tree_intersection(t1, t2) expected = [5, 9, 6] assert actual == expected
walk_one(node.right) walk_one(tree_one.root) def walk_two(node): if node is None: return if node.value in seen: result.append(node.value) walk_two(node.left) walk_two(node.right) walk_two(tree_two.root) return result if __name__ == "__main__": t1 = BinaryTree() t2 = BinaryTree() t1_list = [2, 6, 1, 5, 10, 9, 3, 2] t2_list = [22, 4, 6, 5, 9] for num in t1_list: t1.breadth_add(num) for num in t2_list: t2.breadth_add(num) print(t1.breadth_first()) print(t2.breadth_first()) print(tree_intersection(t1, t2))