def test__init__from_graph(self) -> None: mg = MultiGraph([(1, 2, 5.0, { "color": "red" }), (1, 2, 10.0, { "color": "black" }), (3, 4)]) assert mg.weight == 16.0, "multigraph should have weight 16.0" g = Graph(mg) assert g.has_edge( 1, 2), "graph should have edge (1, 2) copied from multigraph" assert (g.get_edge(1, 2)["color"] == "red" ), "edge (1, 2) should have 'color' attribute set to red" assert g.get_edge( 1, 2).weight == 5.0, "edge (1, 2) should have weight 5.0" assert g.has_edge( 3, 4), "graph should have edge (3, 4) copied from multigraph" assert g.edge_count == 2, "graph should have two edges" assert g.weight == 6.0, "graph should have weight 6.0" assert g.get_edge(1, 2) is not mg.get_edge( # type: ignore 1, 2), "graph should have deep copies of edges and vertices"
def test_remove_edges_from(self) -> None: g = Graph([(1, 2), (2, 3), (3, 4)]) assert g.edge_count == 3, "graph should have 3 edges" g.remove_edges_from([(1, 2), (2, 3)]) assert g.edge_count == 1, "graph should have 1 edge after edge removals" assert g.has_edge(3, 4)