def test_visited_reset(): graph = get_default_graph() for node in graph.graph: assert node.visited == False actual_path = graph.depth_first_search(start=Node("b"), target=Node("a")) for node in graph.graph: assert node.visited == False
def test_sort_default_graph(): graph = get_default_graph() actual_path = graph.topological_sort() expected_path = ["a", "d", "c", "f", "b", "d", "e"] assert actual_path == expected_path
def test_find_node_in_graph(): graph = get_default_graph() expected_path = ["a","c","f"] actual_path = graph.depth_first_search(start=Node("a"), target=Node("f")) assert actual_path == expected_path
def test_start_is_target(): graph = get_default_graph(directed=False) #shouldn't matter expected_path = ["f"] actual_path = graph.depth_first_search(start=Node("f"), target=Node("f")) assert actual_path == expected_path
def test_undirected_graph(): graph = get_default_graph(directed=False) expected_path = ["a","c","f"] actual_path = graph.depth_first_search(start=Node("a"), target=Node("f")) assert actual_path == expected_path
def test_start_not_in_graph(): graph = get_default_graph() with raises(ValueError): graph.depth_first_search(start=Node("w"), target=Node("f"))
def test_no_path(): graph = get_default_graph() actual_path = graph.depth_first_search(start=Node("b"), target=Node("a")) expected_path = [] assert actual_path == expected_path
def test_no_path_from_start_to_target(): graph = get_default_graph() expected_path = [] actual_path = graph.breadth_first_search(start=Node("b"), target=Node("a")) assert actual_path == expected_path
def test_target_not_in_graph(): graph = get_default_graph() expected_path = ["a", "c", "f"] with raises(ValueError): graph.breadth_first_search(start=Node("a"), target=Node("g"))