mirror of
https://github.com/data61/MP-SPDZ.git
synced 2026-04-20 03:01:31 -04:00
51 lines
787 B
Plaintext
51 lines
787 B
Plaintext
# sbitint: factory for signed integer types
|
|
|
|
sint = sbitint.get_type(32)
|
|
|
|
def test(a, b, value_type=None):
|
|
try:
|
|
a = a.reveal()
|
|
except AttributeError:
|
|
pass
|
|
import inspect
|
|
print_ln('line %s: diff %s, got %s, expected %s',
|
|
inspect.currentframe().f_back.f_lineno, \
|
|
(a ^ cbits(b, n=a.n)).reveal(), a, hex(b))
|
|
|
|
a = sint(1)
|
|
b = sint(2)
|
|
|
|
test(a + b, 3)
|
|
test(a + a, 2)
|
|
test(a * b, 2)
|
|
test(a * a, 1)
|
|
test(a - b, -1)
|
|
test(a < b, 1)
|
|
test(a <= b, 1)
|
|
test(a >= b, 0)
|
|
test(a > b, 0)
|
|
test(a == b, 0)
|
|
test(a != b, 1)
|
|
|
|
clear_a = a.reveal()
|
|
|
|
# arrays and loops
|
|
|
|
a = Array(100, sint)
|
|
|
|
@for_range(100)
|
|
def f(i):
|
|
a[i] = sint(i)**2
|
|
|
|
test(a[99], 99**2)
|
|
|
|
# conditional
|
|
|
|
if_then(regint(0))
|
|
a[0] = 123
|
|
else_then()
|
|
a[0] = 789
|
|
end_if()
|
|
|
|
test(a[0], 789)
|