-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_test.py
executable file
·57 lines (45 loc) · 1.36 KB
/
graph_test.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
#!/usr/bin/env python3
'''
Ad-hoc test for graph module
'''
import graph
import configuration as config
class NodeStub:
'''Mock a Room object with an integer'''
def __init__(self, value):
'''Internalize value'''
self.value = value
@property
def name(self):
'''Return name of room'''
return str(self.value)
@property
def collectibles(self):
'''Return collectibles within node'''
return []
@property
def world(self):
'''Return the default'''
return 'default'
@property
def elevator(self):
'''No NodeStubs are elevators'''
return False
if __name__ == '__main__':
config.loadConfiguration('stub_config.json')
g = graph.Graph()
nodes = [graph.GraphNode(NodeStub(i)) for i in range(5)]
deps = [None, None, 'Power', 'Turbo']
for i, j in zip(range(4), deps):
nodes[i].addAdjacency((nodes[i+1], j))
# create cycle
nodes[2].addAdjacency((nodes[1], None))
for n in nodes:
g.addNode(n)
g.write_png('test.png')
# print('\n'.join('%d: %d' % (i, id(k)) for i, k in enumerate(nodes)))
# g.compute_distances([])
# print('\n'.join('%s: %s' % (k, v) for k, v in g.distm.items()))
# print(g.max_degree, g.min_degree, g.diameter, g.radius)
for n in g.depth_first_search(nodes[0], []):
print(n.key)