Beispiel #1
0
def test_strongly_connected_components(graph: DirectedGraph) -> None:
    sccs = graph.strongly_connected_components()
    scc_nodes = list(chain(*sccs))
    nodes = list(graph.nodes())

    assert len(scc_nodes) == len(nodes)
    assert set(scc_nodes) == set(nodes)
Beispiel #2
0
def test_dfs_is_deterministic(graph: DirectedGraph) -> None:
    for node in graph.nodes():
        assert iequal(graph.dfs(node), graph.dfs(node), strict=True)
Beispiel #3
0
def test_topological_sort(graph: DirectedGraph, reverse: bool) -> None:
    sorted_nodes = list(graph.topological_sort(reverse=reverse))
    nodes = list(graph.nodes())

    assert len(sorted_nodes) == len(nodes)
    assert set(sorted_nodes) == set(nodes)