def test_deep_copy(self): v_a = Vertex() v_b = Vertex() e = Edge(v_a, v_b) g = Graph([v_a, v_b], [e]) g_copy = deepcopy(g) self.assertIsNot(g, g_copy) e = g.get_edges().pop() e_copy = g_copy.E.pop() self.assertIsNot(e, e_copy) self.assertEqual(e.get_value(), e_copy.get_value()) self.assertIsNot(e.get_vertices(), e_copy.get_vertices()) self.assertEqual([v.get_value() for v in e.get_vertices()], [v.get_value() for v in e_copy.get_vertices()]) [v.set_value(1) for v in e.get_vertices()] [v.set_value(2) for v in e_copy.get_vertices()] self.assertNotEqual([v.get_value() for v in e.get_vertices()], [v.get_value() for v in e_copy.get_vertices()]) e.set_value(1) e_copy.set_value(2) self.assertEqual(e.get_value(), 1) self.assertEqual(e_copy.get_value(), 2) self.assertEqual(len(g.get_vertices().intersection(g_copy.V)), 0)
def test_one_edge(self): v_zero = Vertex(0) v_one = Vertex(1) e = Edge(v_zero, v_one) self.assertIs(e.get_value(), None) self.assertIsInstance(Graph([v_zero, v_one], [e]), Graph)