-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_triple_lib.mpc
276 lines (193 loc) · 6.4 KB
/
test_triple_lib.mpc
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
from Compiler.triple_lib import (
store_triples_to_db,
load_triples_from_db,
get_next_triple,
get_triples_list,
get_triples_tuple,
get_triples_vectorized,
)
print_ln("----------------------------------- Testing Triple Lib -----------------------------------")
class bcolors:
HEADER = '\033[95m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def test(actual, expected):
total_tests = cint.load_mem(3000)
total_tests += 1
total_tests.store_in_mem(3000)
if_then(actual != expected)
print_ln(bcolors.FAIL + 'FAILURE: expected %s, got %s' +
bcolors.ENDC, expected, actual)
failed_tests = cint.load_mem(6000)
failed_tests += 1
failed_tests.store_in_mem(6000)
else_then()
print_ln(bcolors.OKGREEN + "TEST: %s equals %s" +
bcolors.ENDC, expected, actual)
end_if()
def is_valid_triple(triple):
valid_triple = cint(0)
z = triple[2].reveal() - (triple[0].reveal() * triple[1].reveal())
valid_triple += (z == 0)
return valid_triple
def test_triples(test_size, db=True):
correct_triple = 0
if db:
store_triples_to_db(test_size)
load_triples_from_db(test_size)
for _ in range(test_size):
test_triple = get_next_triple()
comparison = is_valid_triple(test_triple)
correct_triple += comparison
test(correct_triple, test_size)
def test_triples_vectorized(test_size, db=True):
correct_triple = 0
triple_size = 3 * test_size
if db:
store_triples_to_db(test_size)
load_triples_from_db(test_size)
next_triples = get_next_triple(test_size)
test_triples = Array(triple_size, sint)
vstms(triple_size, next_triples, test_triples.address)
for i in range(0, triple_size, 3):
test_triple = test_triples[i:i+3]
correct_triple += is_valid_triple(test_triple)
test(correct_triple, test_size)
def test_triples_list(test_size, db=True):
correct_triple = 0
triple_size = 3 * test_size
if db:
store_triples_to_db(test_size)
load_triples_from_db(test_size)
test_triples = get_triples_list(test_size)
for i in range(0, triple_size, 3):
test_triple = test_triples[i:i+3]
correct_triple += is_valid_triple(test_triple)
test(correct_triple, test_size)
def test_triples_list_tuple(test_size, db=True):
correct_triple = 0
if db:
store_triples_to_db(test_size)
load_triples_from_db(test_size)
test_triples = get_triples_tuple(test_size)
for test_triple in test_triples:
comparison = is_valid_triple(test_triple)
correct_triple += comparison
test(correct_triple, test_size)
def test_triples_vectorized_tuple(test_size, db=True):
correct_triple = 0
if db:
store_triples_to_db(test_size)
load_triples_from_db(test_size)
test_triples = get_triples_vectorized(test_size)
if (test_size == 1):
test_triple = (test_triples[0], test_triples[1], test_triples[2])
correct_triple += is_valid_triple(test_triple)
else:
test_triples_a = Array(test_size, sint)
test_triples_b = Array(test_size, sint)
test_triples_c = Array(test_size, sint)
vstms(test_size, test_triples[0], test_triples_a.address)
vstms(test_size, test_triples[1], test_triples_b.address)
vstms(test_size, test_triples[2], test_triples_c.address)
for i in range(0, test_size):
test_triple = (test_triples_a[i],
test_triples_b[i], test_triples_c[i])
correct_triple += is_valid_triple(test_triple)
test(correct_triple, test_size)
def test_triples_1():
test_size = 1
test_triples(test_size)
def test_triples_100():
test_size = 100
test_triples(test_size)
def test_triples_vectorized_1():
test_size = 1
test_triples_vectorized(test_size)
def test_triples_vectorized_100():
test_size = 100
test_triples_vectorized(test_size)
def test_triples_list_1():
test_size = 1
test_triples_list(test_size)
def test_triples_list_100():
test_size = 100
test_triples_list(test_size)
def test_triples_list_tuple_1():
test_size = 1
test_triples_list_tuple(test_size)
def test_triples_list_tuple_100():
test_size = 100
test_triples_list_tuple(test_size)
def test_triples_vectorized_tuple_1():
test_size = 1
test_triples_vectorized_tuple(test_size)
def test_triples_vectorized_tuple_100():
test_size = 100
test_triples_vectorized_tuple(test_size)
def test_triples_no_db_1():
test_size = 1
db = False
test_triples(test_size, db)
def test_triples_no_db_100():
test_size = 100
db = False
test_triples(test_size, db)
def test_triples_vectorized_no_db_1():
test_size = 1
db = False
test_triples_vectorized(test_size, db)
def test_triples_vectorized_no_db_100():
test_size = 100
db = False
test_triples_vectorized(test_size, db)
def test_triples_list_no_db_1():
test_size = 1
db = False
test_triples_list(test_size, db)
def test_triples_list_no_db_100():
test_size = 100
db = False
test_triples_list(test_size, db)
def test_triples_list_tuple_no_db_1():
test_size = 1
db = False
test_triples_list_tuple(test_size, db)
def test_triples_list_tuple_no_db_100():
test_size = 100
db = False
test_triples_list_tuple(test_size, db)
def test_triples_vectorized_tuple_no_db_1():
test_size = 1
db = False
test_triples_vectorized_tuple(test_size, db)
def test_triples_vectorized_tuple_no_db_100():
test_size = 100
db = False
test_triples_vectorized_tuple(test_size, db)
test_triples_1()
test_triples_100()
test_triples_vectorized_1()
test_triples_vectorized_100()
test_triples_list_1()
test_triples_list_100()
test_triples_list_tuple_1()
test_triples_list_tuple_100()
test_triples_vectorized_tuple_1()
test_triples_vectorized_tuple_100()
test_triples_no_db_1()
test_triples_no_db_100()
test_triples_vectorized_no_db_1()
test_triples_vectorized_no_db_100()
test_triples_list_no_db_1()
test_triples_list_no_db_100()
test_triples_list_tuple_no_db_1()
test_triples_list_tuple_no_db_100()
test_triples_vectorized_tuple_no_db_1()
test_triples_vectorized_tuple_no_db_100()
print_str(
"\n \n TESTS:" + bcolors.OKGREEN + " %s" + bcolors.ENDC +
"/" + bcolors.FAIL + "%s failed" + bcolors.ENDC + "\n \n",
cint.load_mem(3000), cint.load_mem(6000))