Example #1
0
 def test_long_path(self):
     LENGTH = 1000
     g = Graph()
     first, last = add_long_path(g, LENGTH)
     self.assertEqual(len(g.edges), LENGTH)
     self.assertEqual(len(g.nodes), LENGTH + 1)
     dot = g.to_dot('example')
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_cycle(self):
     LENGTH = 5
     g = Graph()
     first = add_cycle(g, LENGTH)
     self.assertEqual(len(g.edges), LENGTH)
     self.assertEqual(len(g.nodes), LENGTH)
     dot = g.to_dot('example')
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 make_trivial_graph():
    """
    Construct a trivial graph:
       a ─> b
    """
    g = Graph()
    a = g.add_node(NamedNode('a'))
    b = g.add_node(NamedNode('b'))
    ab = g.add_edge(a, b)
    return g, a, b, ab
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)