Exemple #1
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])
Exemple #2
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])
Exemple #3
0
def perf_reachable():
    stime = time.time()
    g = build_graph().g
    print "build graph", time.time() - stime, len(g)

    stime = time.time()
    res = g.get_reachable_from(gg.intvector([1]))
    print "get_reachable", time.time() - stime, len(res)
Exemple #4
0
def test_get_links_from_boolvector_empty(small):
    cids = gg.intvector()
    allowed = gg.boolvector()
    small.get_links_from(cids, allowed)
    assert list(allowed) == [False] * 5

    allowed[1] = True
    small.get_links_from(cids, allowed)
    assert list(allowed) == [False, True, False, False, False]
Exemple #5
0
def test_get_links_from_boolvector(small):
    cids = gg.intvector([3, 5])
    allowed = gg.boolvector()
    small.get_links_from(cids, allowed)
    assert list(allowed) == [False, True, False, False, True]
    assert list(cids) == [3, 5]

    allowed = gg.boolvector()
    cids.append(1)
    small.get_links_from(cids, allowed)

    assert list(allowed) == [False, True, True, False, True]
Exemple #6
0
def test_get_links_from_allowed(small):
    cids = gg.intvector([3, 5])
    result = gg.boolvector()
    allowed = gg.boolvector()
    small.get_links_from(cids, result, allowed)
    assert list(result) == [False, False, False, False, False]

    allowed.resize(10)
    small.get_links_from(cids, result, allowed)
    assert list(result) == [False, False, False, False, False]

    allowed[1] = True
    small.get_links_from(cids, result, allowed)
    assert list(result) == [False, True, False, False, False]

    for i in range(10):
        allowed[i] = True
    small.get_links_from(cids, result, allowed)
    assert list(result) == [False, True, False, False, True]
Exemple #7
0
def test_intvector_init_from_list():
    g = gg.intvector(range(100))
    assert list(g) == range(100)
Exemple #8
0
def test_intvector_empty_init():
    g = gg.intvector()
    assert list(g) == []
Exemple #9
0
def test_intvector_append():
    g = gg.intvector()
    for i in range(1000):
        g.append(i)

    assert list(g) == range(1000)
Exemple #10
0
def test_get_links_from_boolvector_return(gr):
    allowed = gg.boolvector()
    cids = gg.intvector()
    cids.append(1)
    res = gr.get_links_from(cids, allowed)
    assert res is allowed
Exemple #11
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]
Exemple #12
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)