Ejemplo n.º 1
0
def test_sort_all_edges_by_dest(graph: Graph):
    original_dests = [[graph.get_edge_dst(e) for e in graph.out_edge_ids(n)]
                      for n in range(NODES_TO_SAMPLE)]
    mapping = sort_all_edges_by_dest(graph)
    new_dests = [[graph.get_edge_dst(e) for e in graph.out_edge_ids(n)]
                 for n in range(NODES_TO_SAMPLE)]
    for n in range(NODES_TO_SAMPLE):
        assert len(original_dests[n]) == len(new_dests[n])
        my_mapping = [mapping[e] for e in graph.out_edge_ids(n)]
        for i, _ in enumerate(my_mapping):
            assert original_dests[n][i] == new_dests[n][
                my_mapping[i] - graph.out_edge_ids(n)[0]]
        original_dests[n].sort()

        assert original_dests[n] == new_dests[n]
Ejemplo n.º 2
0
def test_subgraph_extraction():
    graph = Graph(get_rdg_dataset("rmat15_cleaned_symmetric"))
    sort_all_edges_by_dest(graph)
    nodes = [1, 3, 11, 120]

    expected_edges = [[
        nodes.index(graph.get_edge_dst(e)) for e in graph.out_edge_ids(i)
        if graph.get_edge_dst(e) in nodes
    ] for i in nodes]

    pg = subgraph_extraction(graph, nodes)

    assert isinstance(pg, Graph)
    assert pg.num_nodes() == len(nodes)
    assert pg.num_edges() == 6

    for i, _ in enumerate(expected_edges):
        assert len(pg.out_edge_ids(i)) == len(expected_edges[i])
        assert [pg.get_edge_dst(e)
                for e in pg.out_edge_ids(i)] == expected_edges[i]
Ejemplo n.º 3
0
def test_triangle_count():
    graph = Graph(get_rdg_dataset("rmat15_cleaned_symmetric"))
    original_first_edge_list = [
        graph.get_edge_dst(e) for e in graph.out_edge_ids(0)
    ]
    n = triangle_count(graph)
    assert n == 282617

    n = triangle_count(graph, TriangleCountPlan.node_iteration())
    assert n == 282617

    n = triangle_count(graph, TriangleCountPlan.edge_iteration())
    assert n == 282617

    assert [graph.get_edge_dst(e)
            for e in graph.out_edge_ids(0)] == original_first_edge_list

    sort_all_edges_by_dest(graph)
    n = triangle_count(graph,
                       TriangleCountPlan.ordered_count(edges_sorted=True))
    assert n == 282617