def test_no_path(self): g = Graph() a = g.add_node(Node()) b = g.add_node(Node()) # no edges between them path = g.get_shortest_path(a, b) self.assertEqual(path, []) # FIXME: shouldn't this be None?
def test_long_path(self): LENGTH = 100 g = Graph() first, last = add_long_path(g, LENGTH) path = g.get_shortest_path(first, last) self.assertEqual(len(path), LENGTH) self.assertEqual(path[0].srcnode, first) self.assertEqual(path[-1].dstnode, last)
def test_cycles(self): LENGTH = 5 g = Graph() a = add_cycle(g, LENGTH) b = add_cycle(g, LENGTH) c = add_cycle(g, LENGTH) ab = g.add_edge(a, b) bc = g.add_edge(b, c) path = g.get_shortest_path(a, c) self.assertEqual(len(path), 2) p0, p1 = path self.assertEqual(p0, ab) self.assertEqual(p1, bc)