def test_graph_add_graph(): a = load_graph("test", {'c-a': 'ca', 'c-b': 'cb'}) b = load_graph("test", {'d-e': 'de', 'e-f': 'ef', 'f-g': 'fg'}) c = load_graph("test", { 'c-a': 'ca', 'c-b': 'cb', 'd-e': 'de', 'e-f': 'ef', 'f-g': 'fg' }) assert a.nodecount() + b.nodecount() == c.nodecount() assert a.edgecount() + b.edgecount() == c.edgecount()
def test_graph_shallow_copy(): g = load_graph("test", { 'c-a': 'ca', 'c-b': 'cb', 'b-c': 'bc', 'b-d': 'bd' }) g2 = g.shallow_copy() assert g.edgecount() == g2.edgecount() assert g.nodecount() == g.nodecount()
def test_graph_counts(): g = load_graph("test", {}) assert g.edgecount() == 0 assert g.nodecount() == 0 g = load_graph("test", { 'c-a': 'ca', 'c-b': 'cb', 'c-d': 'cd', 'c-e': 'ce' }) assert g.edgecount() == 4 assert g.nodecount() == 5 g = load_graph("test", { 'c-a': 'ca', 'c-b': 'cb', 'b-c': 'bc', 'b-d': 'bd' }) assert g.edgecount() == 4 assert g.nodecount() == 4
def new_visitor(sorting=False, data=None, extra_data=None): if data is None: data = {'a-b': 'ab', 'b-c': 'bc'} g = load_graph('test-visitor', data) record = AttrDict() record.visited = [] record.origins = {} def tf(d): return extra_data def vf(data, iteration, origin, steps): if data.nid in record.visited: verb("This node was already visited.") return False verb("This node not visited yet.") record.visited.append(data.nid) record.origins[data.nid] = origin return True v = Visitor(g, tf, vf, sorting=sorting) return v, g, record
def test_graph_add_node(): g = load_graph("test", {'c-a': 'ca', 'c-b': 'cb'}) n = Node("n") n2 = g.add_node(n) assert g.node("n") == n assert n2 == n
def test_cycle(): g = load_graph("test-cycle", {'a-b':'ab','b-c':'bc','f-a':'fa','c-e':'ce','e-b':'eb','f-d':'fd'}) cyclic,cycles = CycleDetection.cyclic_nodes(g) cstr = ",".join(sorted(cycles.keys())) assert cstr == 'b->c->e'