Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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"))
Пример #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
Пример #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
Пример #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"))