コード例 #1
0
def test_cached_graph():
    g = Graph(from_list=[(s, e, d + (s / 100)) for s, e, d in graph4x4().edges()])
    g2 = g.copy()
    a, b = 1, 16
    d2, p2 = g2.shortest_path(a, b, memoize=True)
    d1, p1 = g.shortest_path(a, b)
    assert d1 == d2, (d1, d2)
    assert p1 == p2, (p1, p2)
コード例 #2
0
def test_avoids():
    g = graph4x4()
    p = Graph.avoids(g, 1, 16, (3, 7, 11, 10))
    assert p == [1, 5, 9, 13, 14, 15, 16], p
コード例 #3
0
def test_loop():
    g = graph4x4()
    p = Graph.loop(g, 1, 16)
    assert p == [1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 1]
コード例 #4
0
def test_avoids():
    g = graph4x4()
    d, p = Graph.shortest_path(g, 1, 16, avoids={3, 7, 11, 10})
    assert p == [1, 5, 9, 13, 14, 15, 16], p