def _setup_connected(g: Graph): n1 = Node(value="ABC") n2 = Node(value="BCD") g.upsert_node(n1) g.upsert_node(n2) e = Edge(src="ABC", tgt="BCD", edge_value=0) g.add_edge(e) g.save()
def _setup_connected_distant(g: Graph): n1 = Node(value="ABC") n2 = Node(value="BCD") n3 = Node(value="CDE") g.upsert_node(n1) g.upsert_node(n2) g.upsert_node(n3) e1 = Edge(src="ABC", tgt="BCD", edge_value=0) g.add_edge(e1) e2 = Edge(src="BCD", tgt="CDE", edge_value=1) g.add_edge(e2) g.save()
def test_graph_connected_repeats_full_path(g: Graph): n1 = Node(value="ABC") n2 = Node(value="BCD") n3 = Node(value="CDE") g.upsert_node(n1) g.upsert_node(n2) g.upsert_node(n3) e1 = Edge(src="ABC", tgt="BCD", edge_value=0) g.add_edge(e1) e2 = Edge(src="BCD", tgt="CDE", edge_value=1) g.add_edge(e2) e3 = Edge(src="CDE", tgt="ABC", edge_value=2) g.add_edge(e3) e4 = Edge(src="ABC", tgt="BCD", edge_value=3) g.add_edge(e4) e5 = Edge(src="BCD", tgt="CDE", edge_value=4) g.add_edge(e5) g.save() try: paths, _ = g.path('ABC', 'CDE') except: raise GraphException(g) assert len(paths) == 3 c = 0 for path in paths: assert path[0].value == "ABC" assert path[-1].value == "CDE" if len(path) == 3: assert path[1].value == "BCD" # There are 2 copies of this c += 1 elif len(path) == 6: assert path[1].value == "BCD" assert path[2].value == "CDE" assert path[3].value == "ABC" assert path[4].value == "BCD" assert path[5].value == "CDE" assert c == 2
def test_graph_connected_repeats_one_long_path(g: Graph): n1 = Node(value="ABC") n2 = Node(value="BCD") n3 = Node(value="CDE") n4 = Node(value="DEF") g.upsert_node(n1) g.upsert_node(n2) g.upsert_node(n3) g.upsert_node(n4) e1 = Edge(src="ABC", tgt="BCD", edge_value=0) g.add_edge(e1) e2 = Edge(src="BCD", tgt="CDE", edge_value=1) g.add_edge(e2) e3 = Edge(src="CDE", tgt="BCD", edge_value=2) g.add_edge(e3) e4 = Edge(src="BCD", tgt="CDE", edge_value=3) g.add_edge(e4) e4 = Edge(src="CDE", tgt="DEF", edge_value=4) g.add_edge(e4) g.save() paths, _ = g.path('ABC', 'DEF') assert len(paths) == 1
def _setup_connected_multiple(g: Graph): n1 = Node(value="ABC") n2 = Node(value="BCD") n2_alt = Node(value="XYZ") n3 = Node(value="CDE") g.upsert_node(n1) g.upsert_node(n2) g.upsert_node(n3) g.upsert_node(n2_alt) e1 = Edge(src="ABC", tgt="BCD", edge_type="path1", edge_value=0) g.add_edge(e1) e2 = Edge(src="BCD", tgt="CDE", edge_type="path1", edge_value=1) g.add_edge(e2) e1_alt = Edge(src="ABC", tgt="XYZ", edge_type="path2", edge_value=0) g.add_edge(e1_alt) e2_alt = Edge(src="XYZ", tgt="CDE", edge_type="path2", edge_value=1) g.add_edge(e2_alt) g.save()
def _setup_connected_shortcut(g: Graph): n1 = Node(value="ABC") n2 = Node(value="BCD") n3 = Node(value="CDE") g.upsert_node(n1) g.upsert_node(n2) g.upsert_node(n3) e1 = Edge(src="ABC", tgt="BCD", edge_type="path1", edge_value=0) g.add_edge(e1) e2 = Edge(src="BCD", tgt="CDE", edge_type="path1", edge_value=1) g.add_edge(e2) e1_short = Edge(src="ABC", tgt="CDE", edge_type="path2", edge_value=0) g.add_edge(e1_short) g.save()