Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
def test_start_not_in_graph():
    graph = get_default_graph()
    with raises(ValueError):
        graph.depth_first_search(start=Node("w"), target=Node("f"))
Example #7
0
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
Example #8
0
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
Example #9
0
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"))