-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
59 lines (46 loc) · 961 Bytes
/
test.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
from cantor import *
def test_q(a, b):
assert q_decode(q_encode(a, b)) == (a, b)
return q_encode(a, b)
def test_z(z):
assert z_decode(z_encode(z)) == z
return z_encode(z)
def run():
for i in range(2**10):
test_q(i , i)
test_q(i, -i)
test_q(-i, i)
test_q(-i, -i)
test_q(i , i//3)
test_q(i, -i//3)
test_q(-i, i//3)
test_q(-i, -i//3)
test_q(i, 0)
test_q(0, i)
test_q(-i, 0)
test_q(0, -i)
test_z(i)
test_z(-i)
try:
z_decode(0)
assert(False)
except ValueError:
pass
try:
z_decode(-1)
assert(False)
except ValueError:
pass
try:
q_decode(0)
assert(False)
except ValueError:
pass
try:
q_decode(-1)
assert(False)
except ValueError:
pass
return "Ok"
if __name__ == '__main__':
print(run())