Ejemplo n.º 1
0
 def test_edges_and_edge_count(self) -> None:
     g = MultiGraph([(1, 2), (2, 1), (2, 3), (3, 4)])
     assert set(g.edges()) == {
         g.get_edge(1, 2),
         g.get_edge(2, 3),
         g.get_edge(3, 4),
     }, "multiedges should be (1, 2), (2, 3), (3, 4)"
     assert g.edge_count == 4, "graph should have 4 edge connections"
     assert (g.get_edge(1, 2).multiplicity == 2
             ), "multiedge (1, 2) should have two parallel connections"
Ejemplo n.º 2
0
    def test_multigraph_read_adj_list02(self) -> None:
        g = MultiGraph()
        read_adj_list(os.path.join(os.getcwd(), TEST_DIR, GRAPH_FILE02), g)

        assert g.edge_count == len(
            g.edges()), "g should have no parallel edges"
        assert g.edge_count == 6, "graph should have 6 edges"
        assert g.vertex_count == 4, "graph should have 4 vertices"
        assert g[1].degree == g[2].degree, "v1 and v2 should have same degree"
        assert g[1].degree == 3, "v1 should have degree 3"
        assert g.get_edge(2, 4) is not None, "graph should have edge (2, 4)"
        assert g.get_edge(1, 3) is not None, "graph should have edge (1, 3)"
Ejemplo n.º 3
0
    def test_multigraph_read_adj_list03(self) -> None:
        g = MultiGraph()
        read_adj_list(os.path.join(os.getcwd(), TEST_DIR, GRAPH_FILE03), g)

        assert g.edge_count == len(
            g.edges()), "g should have no parallel edges"
        assert g.edge_count == 14, "graph should have 14 edges"
        assert g.vertex_count == 8, "graph should have 8 vertices"
        assert g[1].degree < g[2].degree, "v1 and v2 should have same degree"
        assert g[1].degree == 3, "v1 should have degree 3"
        assert g[2].degree == 4, "v2 should have degree 4"
        assert g.get_edge(2, 4) is not None, "graph should have edge (2, 4)"

        with pytest.raises(KeyError):
            assert g.get_edge(2,
                              6) is None, "graph should not have edge (2, 6)"