Exemple #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?
Exemple #2
0
def add_long_path(g, length):
    """
    Construct a path of the form:
        first -> n0 -> n1 -> .... -> last
    where there are "length" edges
    """
    first = g.add_node(Node())
    last = first
    cur = first
    for i in range(length):
        last = g.add_node(Node())
        g.add_edge(cur, last)
        cur = last
    return first, last