def test_incident_edges_and_loop_edge(self) -> None: g = MultiGraph() g.add_vertex(0) assert not g[0].loop_edge, "vertex 0 should not have a loop edge" g.add_edges_from([(1, 1), (1, 1), (2, 3), (2, 3)]) assert g[1].incident_edges() == {g.get_edge( 1, 1)}, "vertex 1 should have self loop as incident edge" assert g[1].loop_edge, "vertex 1 should have a self loop" assert len(g[2].incident_edges() ) == 1, "vertex 2 should have one incident multiedge" assert (next(iter(g[2].incident_edges())).multiplicity == 2 ), "multiedge (2, 3) should have multiplicity 2"
def test_issubclass_and_isinstance(self) -> None: g = MultiGraph() v1 = g.add_vertex(1) assert isinstance( v1, vertex_module.VertexBase ), "v1 should be an instance of superclass VertexBase" assert isinstance(v1, MultiVertex), "v1 should be a MultiVertex instance" assert issubclass(MultiVertex, vertex_module.VertexBase ), "MultiVertex should be VertexBase subclass"
def test_degree(self) -> None: g = MultiGraph() v0 = g.add_vertex(0) assert v0.degree == 0, "vertex 0 should have degree 0" g.add_edge(1, 1) assert g[1].degree == 2, "vertex with self loop should have degree 2" g.add_edge(1, 1) assert g[ 1].degree == 4, "vertex with two parallel self loops should have degree 4" g.add_edge(2, 3) assert g[2].degree == 1, "vertex 2 should have degree 1" g.add_edge(2, 3) assert g[ 2].degree == 2, "vertex 2 with two parallel edge connections should have degree 2"
def test_is_vertex_type(self) -> None: g = Graph() v: Vertex = g.add_vertex(1) assert vertex_module.is_vertex_type( v), "Vertex object should be a VertexType" g2 = DiGraph() di_v: DiVertex = g2.add_vertex(1) assert vertex_module.is_vertex_type( di_v), "DiVertex object should be a VertexType" g3 = MultiGraph() multi_v: MultiVertex = g3.add_vertex(1) assert vertex_module.is_vertex_type( multi_v), "MultiVertex object should be a VertexType" g4 = MultiDiGraph() multi_di_v: MultiDiVertex = g4.add_vertex(1) assert vertex_module.is_vertex_type( multi_di_v), "MultiDiVertex should be a VertexType" assert vertex_module.is_vertex_type( 10), "int vertex label should be a VertexType" assert vertex_module.is_vertex_type( "s"), "str vertex label should be a VertexType" assert vertex_module.is_vertex_type(("s", { "color": "blue" })), "vertex tuple should be a VertexType" assert not vertex_module.is_vertex_type( 10.99), "float should not be a VertexType" assert not vertex_module.is_vertex_type( ("s", "t")), "edge tuple should not be a VertexType" assert not vertex_module.is_vertex_type( ("s", "t", 4.5)), "edge tuple with edge weight should not be a VertexType" g.add_edge("s", "t") assert not vertex_module.is_vertex_type(g.get_edge( "s", "t")), "edge object should not be a VertexType"