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])
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])
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
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
def __init__(self): self.g = gg.graph() self.cid = 0 self.make_container(self.getcid(), 6)
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
def test_iter_empty(): assert list(gg.graph()) == []
def pytest_funcarg__small(request): small = gg.graph() for x in small_links: small.add_link(*x) return small
def test_maxstartnode(): g = gg.graph() g.add_link(1, 3) assert g.maxstartnode() == 1 assert g.maxendnode() == 3
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]
def test_get_reachable_from_empty_graph(): g = gg.graph() res = g.get_reachable_from(gg.intvector(range(10))) assert list(res) == range(10)