def test_two_sum_iv(): tree = TreeNode(1) assert not two_sum_iv(tree, 2) tree = get_binary_tree() assert two_sum_iv(tree, 5) assert not two_sum_iv(tree, 1) assert not two_sum_iv(tree, 10)
def test_inorder_traversal_stack(): tree = get_binary_tree() assert inorder_traversal_stack(tree) == [4, 2, 5, 1, 3]
def test_postorder_traversal_recursive(): tree = get_binary_tree() assert postorder_traversal_iterative(tree) == [4, 5, 2, 3, 1]
def test_min_depth_bfs(): tree = get_binary_tree() assert min_depth_bfs(tree) == 2
def test_find_mode(): tree = get_binary_tree() assert sorted(find_mode(tree)) == [1, 2, 3, 4, 5] tree.left.right.left = TreeNode(5) assert find_mode(tree) == [5]
def test_max_depth(): tree = get_binary_tree() assert max_depth(tree) == 3
def test_has_path_sum(): assert has_path_sum(get_binary_tree(), 4) assert has_path_sum(get_binary_tree(), 7) assert has_path_sum(get_binary_tree(), 8) assert has_path_sum(TreeNode(1), 1)
def test_level_order_traversal(): tree = get_binary_tree() assert level_order_traversal(tree) == [[1], [2, 3], [4, 5]]