Ejemplo n.º 1
0
def test_get_reachable_from_cyclic():
    g = gg.graph()
    g.add_link(1, 2)
    g.add_link(2, 3)
    g.add_link(3, 1)
    res = g.get_reachable_from(gg.intvector([1]))
    assert set(res) == set([1, 2, 3])
Ejemplo n.º 2
0
def test_get_reachable_from():
    g = gg.graph()
    g.add_link(1, 2)
    g.add_link(1, 3)
    g.add_link(2, 4)
    res = g.get_reachable_from(gg.intvector([1]))
    assert set(res) == set([1, 2, 3, 4])

    res = g.get_reachable_from(gg.intvector([4]))
    assert set(res) == set([4])
Ejemplo n.º 3
0
def test_graph_len():
    g = gg.graph()
    assert len(g) == 0

    g.add_link(1, 2)
    assert len(g) == 1

    g.add_link(1, 2)
    assert len(g) == 1

    g.add_link(2, 1)
    assert len(g) == 2
Ejemplo n.º 4
0
Archivo: ggext.py Proyecto: schmir/gg
def readcsv(fn, g=None):
    stime=time.time()
    if g is None:
        g = graph()

    count=0
    add_link = g.add_link
    for x in open(fn, "rb"):
        try:
            s, e = map(int, x.split())
        except ValueError:
            pass
        else:
            add_link(s,e)
            count += 1

    print "read %s links in %ss" % (count,time.time()-stime)
    return g
Ejemplo n.º 5
0
 def __init__(self):
     self.g = gg.graph()
     self.cid = 0
     self.make_container(self.getcid(), 6)
Ejemplo n.º 6
0
def pytest_funcarg__gr(request):
    gr = gg.graph()
    for i in range(100):
        for j in range(i):
            gr.add_link(i, j)
    return gr
Ejemplo n.º 7
0
def test_iter_empty():
    assert list(gg.graph()) == []
Ejemplo n.º 8
0
def pytest_funcarg__small(request):
    small = gg.graph()
    for x in small_links:
        small.add_link(*x)
    return small
Ejemplo n.º 9
0
def test_maxstartnode():
    g = gg.graph()
    g.add_link(1, 3)

    assert g.maxstartnode() == 1
    assert g.maxendnode() == 3
Ejemplo n.º 10
0
def test_get_reachable_from_multiple_parents():
    g = gg.graph()
    g.add_link(1, 3)
    g.add_link(2, 3)
    res = g.get_reachable_from(gg.intvector([1, 2]))
    assert list(res) == [1, 2, 3]
Ejemplo n.º 11
0
def test_get_reachable_from_empty_graph():
    g = gg.graph()
    res = g.get_reachable_from(gg.intvector(range(10)))
    assert list(res) == range(10)