def test_add_connect(self): g = Graph(directed=True) g.add_vertices(1, 2, 3) g.connect(1, 2) g.connect(2, 3) self.assertEqual(g.Vertices, {1, 2, 3}) self.assertEqual(g.Edges, {(1, 2), (2, 3)}) self.assertEqual(g._successors, {1: {2}, 2: {3}, 3: set()}) self.assertEqual(g._antecessors, {1: set(), 2: {1}, 3: {2}})
def test_constructor_undirected(self): g = Graph(directed=False) g.add_vertices(1, 2, 3) g.connect(1, 2) g.connect(2, 3) h = Graph({1, 2, 3}, {(1, 2), (2, 1), (2, 3), (3, 2)}, directed=False) self.assertEqual(g.Vertices, h.Vertices) self.assertEqual(g.Edges, h.Edges) self.assertEqual(g._successors, h._successors) self.assertEqual(g._antecessors, h._antecessors)