def test_is_regular_should_return_true_for_regular(self): """Should return true when each node has the same number of edges""" vertices = [Vertex('a'), Vertex('b'), Vertex('9')] g = Graph(vertices, []) g.add_regular_edges() self.assertTrue(g.is_regular())
def test_regular_edges_fail_when_edges_exist(self): """should raise exception when edge exists""" vertices = [Vertex('a'), Vertex('b')] e = Edge(*vertices) g = Graph(vertices) g.add_edge(e) with self.assertRaises(Exception): g.add_regular_edges()
def test_regular_edges_works_with_three_vertices(self): """to build .add_regular_edges, we'll need a way tp count a Vertex's number of edges""" vertices = [Vertex('a'), Vertex('b'), Vertex('c')] g = Graph(vertices, []) g.add_regular_edges() self.assertTrue(len(g.edges()) == 3) self.assertTrue(g.is_regular())
def test_regular_edges_works_with_six_vertices(self): """to build .add_regular_edges, we'll need a way tp count a Vertex's number of edges""" import string six_letters = [c for c in string.ascii_lowercase][:6] vertices = [Vertex(l) for l in six_letters] g = Graph(vertices, []) g.add_regular_edges() #pp = pprint.PrettyPrinter() #pp.pprint(g) self.assertTrue(len(g.edges()) == 6) self.assertTrue(g.is_regular())