-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtest_memory.py
98 lines (87 loc) · 2.55 KB
/
test_memory.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
87
88
89
90
91
92
93
94
95
96
97
98
from openalea.lpy import *
#def test_String( nb = 1, size = 100):
# """ Test creation of str """
# for i in xrange(nb):
# a = 'F'*size
# del a
#maxsize = 10000
#maxlength = 8
maxsize = 100
maxlength = 3
def test_AT( nb = maxlength, size = maxsize):
""" Test creation of AxialTree """
for i in range(nb):
a = AxialTree('F'*size)
del a
def test_PAT( nb = maxlength, size = maxsize):
""" Test creation of Parametric AxialTree """
for i in range(nb):
a = AxialTree()
for j in range(size):
a += 'F('+str(j)+')'
del a
def test_LsRuleWithGlobalContext():
""" Test creation of LsysRule with global context """
l = LsysRule()
try:
l.set('F --> F')
except NameError as e :
import warnings
warnings.warn("GlobalContext has not lpy symbols")
def test_LsRule():
""" Test creation of LsysRule """
lc = LsysContext()
lc.makeCurrent()
res = 'F[+F]F[-F]F'
l = LsysRule()
l.set('F --> '+res)
assert l.isCompiled(), "LsysRule.compile did not work."
assert l.forwardCompatible() == True and l.backwardCompatible() == True
assert l.isContextFree() == True and l.nbContexts() == 0
assert l.nbParameters() == 0
#assert len(l()) == len(res)
assert len(l.process('FF')) == 2*len(res)
assert l.match('F',0)[0] == 1
assert l.reverse_match('FFF')[0] == 1
def lnLs(l = 8):
if l == 0: return 1
elif l == 1: return 11
else:
res = 6
a = 5
for i in range(l-2):
res += a*6
a *= 5
res += a*11
return res
def test_Ls( nb = 1, length = maxlength):
""" Test creation and execution of Lsystems """
l = Lsystem()
l.derivationLength = length
l.axiom = AxialTree('F')
l.addProductionRule('F --> F[+F]F[-F]F',0)
ln = lnLs(length)
for i in range(nb):
a = l.iterate()
assert len(a) == ln
del a
del l
def test_PLs( nb = 1, length = maxlength):
""" Test creation and execution of Parametric Lsystems """
l = Lsystem()
l.derivationLength = length
l.axiom = AxialTree('F(0)')
l.addProductionRule('F(x) --> F(x+1)[+F(x)]F(x+1)[-F(x)]F(x+1)',0)
ln = lnLs(length)
for i in range(nb):
a = l.iterate()
assert len(a) == ln
del a
del l
if __name__ == '__main__':
test_AT()
test_PAT()
test_LsRuleWithGlobalContext()
test_LsRule()
test_Ls()
test_PLs()