def test_graph_conversions(): igraph = ig.Graph.Star(6) g = Graph.from_igraph(igraph) assert g.n_nodes == igraph.vcount() assert g.edges() == igraph.get_edgelist() assert all(c == 0 for c in g._edge_colors) nxg = nx.star_graph(5) g = Graph.from_networkx(nxg) assert g.n_nodes == igraph.vcount() assert g.edges() == igraph.get_edgelist() assert all(c == 0 for c in g._edge_colors) igraph = ig.Graph() igraph.add_vertices(3) igraph.add_edges( [(0, 1), (1, 2)], attributes={ "color": ["red", "blue"], }, ) with pytest.raises(ValueError, match="not all colors are integers"): _ = Graph.from_igraph(igraph) igraph = ig.Graph() igraph.add_vertices(3) igraph.add_edges( [(0, 1), (1, 2)], attributes={ "color": [0, 1], }, ) g = Graph.from_igraph(igraph) assert g.edges(color=0) == [(0, 1)] assert g.edges(color=1) == [(1, 2)]
def test_is_bipartite(): for i in range(1, 10): for j in range(1, i * i): x = nx.dense_gnm_random_graph(i, j) y = Graph.from_networkx(x) if len(x) == len( set((i for (i, j) in x.edges())) | set((j for (i, j) in x.edges())) ): assert y.is_bipartite() == nx.is_bipartite(x)
def test_is_connected(): for i in range(5, 10): for j in range(i + 1, i * i): x = nx.dense_gnm_random_graph(i, j) y = Graph.from_networkx(x) if len(x) == len( set((i for (i, j) in x.edges)) | set((j for (i, j) in x.edges)) ): assert y.is_connected() == nx.is_connected(x) else: assert not nx.is_connected(x)