-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbpg_test.py
More file actions
executable file
·80 lines (67 loc) · 1.97 KB
/
bpg_test.py
File metadata and controls
executable file
·80 lines (67 loc) · 1.97 KB
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
#!/usr/bin/python
import os
import unittest
import random
import pickle
import sys
import testoob
import bpg
import node
import test_common
from test_common import *
from plot import *
class BodyPartTest(unittest.TestCase):
def test_0_init(self):
self.bp = bpg.BodyPart(new_network_args)
class BodyPartGraphTest(unittest.TestCase):
def setUp(self):
if not os.path.exists('test'):
os.mkdir('test')
self.fprefix = 'test/bpg_'
def tearDown(self):
pass
def gv(self, f):
if test_common.interactive:
os.system('kpdf %s.pdf'%f)
def test_1_init(self):
self.bpg = new_individual_fn(**new_individual_args)
self.bpg.sanityCheck()
def test_2_plotBpg(self):
self.test_1_init()
fname = self.fprefix + 'plotBpg'
plotBpg(self.bpg, fname+'.pdf')
self.gv(fname)
def test_3_plotNetworks(self):
self.test_1_init()
fname = self.fprefix + 'plotNetworks'
plotNetworks(self.bpg, fname+'.pdf', 0)
self.gv(fname)
def test_4_unroll(self):
self.test_1_init()
f = open(self.fprefix+'unroll_before.pickle','w')
pickle.dump(self.bpg, f)
f.close()
# root node should be in list
assert self.bpg.root
assert self.bpg.bodyparts.index(self.bpg.root) >= 0
# -> ps
fname = self.fprefix + 'unroll_before'
plotBpg(self.bpg, fname+'.dot')
plotBpg(self.bpg, fname+'.pdf')
self.gv(fname)
ur_bpg = self.bpg.unroll()
ur_bpg.sanityCheck()
f = open(self.fprefix+'unroll_after.pickle','w')
pickle.dump(ur_bpg, f)
f.close()
# -> ps
fname = self.fprefix + 'unroll_after'
plotBpg(ur_bpg, fname+'.dot')
plotBpg(ur_bpg, fname+'.pdf')
self.gv(fname)
def test_5_mutate(self):
self.test_1_init()
for _ in range(3):
self.bpg.mutate(1)
if __name__ == "__main__":
test_main()