Example #1
0
 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?
Example #2
0
 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?
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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)