def test_repr_str_and_label(self) -> None: mg = MultiGraph([(2, 1), (1, 2)]) assert mg.get_edge( 2, 1).label == "(1, 2)", "multiedge label should be (1, 2)" assert (mg.get_edge(2, 1).__str__() == mg.get_edge( 2, 1).__repr__()), "edge __repr__ should equal __str__" assert (mg.get_edge(2, 1).__str__() == "(1, 2), (1, 2)" ), "edge __str__ should be '(1, 2), (1, 2)'" mg.add_edge(3, 4, weight=1.5) assert mg.get_edge( 2, 1).label == "(1, 2)", "multiedge label should be (1, 2)" assert ( mg.get_edge(2, 1).__str__() == "(1, 2, 1.0), (1, 2, 1.0)" ), "edge __str__ should be '(1, 2, 1.0), (1, 2, 1.0)' after adding weighted edge to graph"
def test_issubclass_and_isinstance(self) -> None: g = MultiGraph() edge: MultiEdge = g.add_edge(1, 2) assert isinstance( edge, edge_module.MultiEdgeBase ), "edge should be an instance of superclass MultiEdgeBase" assert isinstance(edge, MultiEdge), "edge should be an MultiEdge instance" assert issubclass(MultiEdge, edge_module.MultiEdgeBase ), "MultiEdge should be MultiEdgeBase 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"