-
Notifications
You must be signed in to change notification settings - Fork 10
/
testing_get_missing_in_between_nodes.py
55 lines (51 loc) · 1.49 KB
/
testing_get_missing_in_between_nodes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import networkx as nx
import builtins
builtins.DONT_LOAD_GRAPH = True
from backend.routes.graph import get_missing_in_between_nodes, test_get_missing_in_between_nodes
print_stack = lambda s: '; '.join([f"""{n}{'<--' if p else ''}{','.join(p)}""" for n,p in reversed(s)])
def get_missing(edges, subgraph_nodes, verbose=False):
G = nx.DiGraph(edges)
n = get_missing_in_between_nodes(G, subgraph_nodes, verbose=verbose)
print(f"Found {n} missing nodes\n")
return n
graph_as_ascii = """
a
/ \
b i
/ |
| j
c___/
|
d___
/ \ \
e h g
| |
\ /
f
"""
test_edges = [
('a', 'b'),
('c', 'd'),
('a', 'i'),
('i', 'j'),
('b', 'c'),
('j', 'c'),
('d', 'e'),
('d', 'g'),
('d', 'h'),
('e', 'f'),
('h', 'f'),
# ('j', 'k'), # extra nodes beyond the real-life example, for some other testing
# ('l', 'h'),
# ('k', 'h'),
]
# subgraph_nodes = ['f', 'd', ]
# expected_missing_in_between_nodes = ['e', 'h']
subgraph_nodes = ['f', 'd', 'i',]
expected_missing_in_between_nodes = ['e', 'h', 'c', 'j']
# subgraph_nodes = ['f', 'd', 'g', 'k']
test_get_missing_in_between_nodes(test_edges,
subgraph_nodes=subgraph_nodes,
expected_missing_in_between_nodes=expected_missing_in_between_nodes,
fail=False)
# get_missing(test_edges, subgraph_nodes)