-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpynodes.py
86 lines (68 loc) · 1.76 KB
/
pynodes.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from abc import ABCMeta, abstractmethod
import concurrent.futures
import time
from collections import defaultdict
import queue
from graph import Graph, GraphNode, Node
class A(Node):
def __init__(self, val, name):
self.val = val
self.setName(name)
def execute(self, args):
if self.val == 1:
return 1
else:
return 0
class B(Node):
def __init__(self, name):
self.setName(name)
def execute(self, args):
if args[0] == 1:
return 'world'
elif len(args) > 1 and args[1] == 1:
return 'words'
else:
return 'heckles'
def one():
a = GraphNode('a', A(1, 'a'))
b = GraphNode('b', B('b'))
c = GraphNode('c', A(1, 'c'))
b1 = GraphNode('b1', B('b1'))
b2 = GraphNode('b2', B('b2'))
g = Graph(a)
g.connect(a, [b, c])
g.connect(c, [b1])
g.connect(c, [b2])
g.connect(b1, [b2])
Graph.executeGraph(g)
assert b2.future.result() == 'world'
def two():
a = GraphNode('a', A(1, 'a'))
b = GraphNode('b', B('b'))
c = GraphNode('c', A(1, 'c'))
b1 = GraphNode('b1', A(1, 'b1'))
b2 = GraphNode('b2', B('b2'))
g = Graph(a)
g.connect(a, [b, c])
g.connect(c, [b1])
g.connect(c, [b2])
g.connect(b1, [b2])
Graph.executeGraph(g)
assert b2.future.result() == 'world'
def three():
a = GraphNode('a', A(1, 'a'))
b = GraphNode('b', B('b'))
c = GraphNode('c', A(9, 'c'))
b1 = GraphNode('b1', A(2, 'b1'))
b2 = GraphNode('b2', B('b2'))
g = Graph(a)
g.connect(a, [b, c])
g.connect(c, [b1])
g.connect(c, [b2])
g.connect(b1, [b2])
Graph.executeGraph(g)
assert b2.future.result() == 'heckles'
if __name__ == '__main__':
one()
two()
three()