-
Notifications
You must be signed in to change notification settings - Fork 25
/
test_list_scalar.py
146 lines (95 loc) · 3.95 KB
/
test_list_scalar.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
'''
Created on Jun 21, 2020
@author: ballance
'''
import vsc
from vsc_test_case import VscTestCase
from vsc.visitors.model_pretty_printer import ModelPrettyPrinter
class TestListScalar(VscTestCase):
@vsc.randobj
class my_item_c(object):
def __init__(self):
self.fixed = vsc.rand_list_t(vsc.bit_t(8), sz=4)
self.dynamic = vsc.randsz_list_t(vsc.bit_t(8))
self.queue = vsc.randsz_list_t(vsc.bit_t(8))
def test_randsz_smoke(self):
@vsc.randobj
class my_item_c(object):
def __init__(self):
self.l = vsc.randsz_list_t(vsc.uint8_t())
@vsc.constraint
def l_c(self):
self.l.size in vsc.rangelist(vsc.rng(2,10))
self.l[1] == (self.l[0]+1)
it = my_item_c()
it.randomize()
print("it.l.size=" + str(it.l.size))
for i,v in enumerate(it.l):
print("v[" + str(i) + "] = " + str(v))
self.assertEqual(it.l[1], it.l[0]+1)
def test_randsz_len(self):
@vsc.randobj
class my_item_c(object):
def __init__(self):
self.l = vsc.randsz_list_t(vsc.uint8_t())
@vsc.constraint
def l_c(self):
self.l.size in vsc.rangelist(vsc.rng(2,10))
self.l[1] == (self.l[0]+1)
it = my_item_c()
it.randomize()
self.assertGreaterEqual(len(it.l), 2)
self.assertLessEqual(len(it.l), 10)
print("it.l.size=" + str(it.l.size))
for i,v in enumerate(it.l):
print("v[" + str(i) + "] = " + str(v))
self.assertEqual(it.l[1], it.l[0]+1)
def test_randsz_foreach_idx(self):
@vsc.randobj
class my_item_c(object):
def __init__(self):
self.l = vsc.randsz_list_t(vsc.uint8_t())
self.a = vsc.rand_uint8_t()
@vsc.constraint
def l_c(self):
self.l.size in vsc.rangelist(vsc.rng(2,10))
with vsc.foreach(self.l, it=False, idx=True) as idx:
with vsc.if_then(idx > 0):
self.l[idx] == self.l[idx-1]+1
it = my_item_c()
it.randomize()
for i in range(len(it.l)):
if i > 0:
self.assertEqual(it.l[i], it.l[i-1]+1)
def test_fixedsz_foreach_idx(self):
@vsc.randobj
class my_item_c(object):
def __init__(self):
self.a = vsc.rand_uint8_t()
self.b = vsc.rand_uint8_t()
self.temp = vsc.list_t(vsc.uint8_t())
self.temp = [1,3,4,12,13,14]
@vsc.constraint
def ab_c(self):
self.a in vsc.rangelist(1,2,3)
with vsc.foreach(self.temp, idx=True) as i:
self.a != self.temp[i]
it = my_item_c()
for i in range(10):
it.randomize()
self.assertEqual(it.a, 2)
def disabled_test_sum_simple(self):
@vsc.randobj
class my_item_c(object):
def __init__(self):
self.l = vsc.rand_list_t(vsc.uint8_t(), sz=5)
self.a = vsc.rand_uint8_t()
@vsc.constraint
def sum_c(self):
self.l.sum == 5
with vsc.foreach(self.l) as it:
it != 0
it = my_item_c()
it.randomize()
print("Model: " + ModelPrettyPrinter.print(it.get_model()))
self.assertEqual(it.l.sum, 5)