コード例 #1
0
ファイル: test_dfs.py プロジェクト: camjamesjoy/graphs
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
ファイル: test_dfs.py プロジェクト: camjamesjoy/graphs
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
ファイル: test_dfs.py プロジェクト: camjamesjoy/graphs
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
ファイル: test_dfs.py プロジェクト: camjamesjoy/graphs
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
ファイル: test_dfs.py プロジェクト: camjamesjoy/graphs
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
ファイル: test_dfs.py プロジェクト: camjamesjoy/graphs
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"))