-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsymtest.py
executable file
·106 lines (90 loc) · 2.29 KB
/
symtest.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
99
100
101
102
103
104
105
106
#!/usr/bin/env python
from simsym import *
from symtypes import *
def test():
# Maps
x = tmap(SInt, SBool).var("ib")
x[1], x[2] = True, False
assert x[1] == True
assert x[2] == False
# Maps of maps
x = tmap(SInt, tmap(SInt, SBool)).var("iib")
x[0][1], x[1][0] = True, False
assert x[0][1] == True
assert x[1][0] == False
# Structs
x = tstruct(a=SInt, b=SBool, c=SInt, d=SInt).var("s1")
x.a, x.b, x.c = 1, True, x.d
assert x.a == 1
assert x.b == True
assert x.c == x.d
# Constant maps
x = tmap(SInt, SInt).constVal(42)
x[0] = 24
assert x[0] == 24
assert x[1] == 42
# Nested constant maps
t1 = tmap(SInt, SInt)
x = tmap(SInt, t1).constVal(t1.constVal(42))
assert x[0][0] == 42
# Constant structs
x = tstruct(a=SInt, b=SBool).var("s2", a=42)
assert x.a == 42
# Maps of constant structs
t1 = tstruct(a=SInt, b=SBool)
x = tmap(SInt, t1).constVal(t1.var("s3", a=42))
assert x[0].a == 42
assert x[0].b == x[1].b
# Structs of constant maps
t1 = tmap(SInt, SInt)
x = tstruct(a=t1).var(a=t1.constVal(42))
assert x.a[0] == 42
# Assignment of structs in maps
t1 = tstruct(a=SInt, b=SBool)
x = tmap(SInt, t1).var()
x[0] = t1.var(a=42, b=True)
assert x[0].a == 42
assert x[0].b == True
# Assignment of structs in maps with symbolic index
i = SInt.var()
x[i] = t1.var(a=43, b=False)
assert x[i].a == 43
assert x[i].b == False
# Assignment of a whole struct
t1 = tstruct(a=SInt, b=SBool)
t2 = tstruct(sub=t1)
x = t2.var()
x.sub = t1.var(a=42, b=True)
assert x.sub.a == 42
assert x.sub.b == True
# Sets
t1 = tset(SInt)
assert not t1.empty().contains(1)
# Lists
ilist = tlist(SInt)
l1 = ilist.var(_len = 0)
l2 = ilist.var(_len = 0)
l1.append(1)
l2.append(1)
assert l1[0] == l2[0]
assert l1 == l2
l2[0] = 2
assert l1 != l2
l2.append(1)
assert l1 != l2
l2.shift()
assert l1 == l2
# Dicts
idict = tdict(SInt, SInt)
d1 = idict.empty()
d2 = idict.empty()
assert d1 == d2
d1[0] = 1
assert d1 != d2
d2[0] = 1
assert d1 == d2
d1[0] = 2
assert d1 != d2
del d1[0], d2[0]
assert d1 == d2
list(symbolic_apply(test))