forked from perrygeo/pairing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·35 lines (25 loc) · 732 Bytes
/
test.py
File metadata and controls
executable file
·35 lines (25 loc) · 732 Bytes
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
#!/usr/bin/env python
from __future__ import print_function
from pairing import pair, depair
import timeit
def test_pair(a, b):
assert depair(pair(a, b)) == (a, b)
return pair(a, b)
def run_tests():
test_pair(22, 33)
test_pair(2**8, 2**8)
test_pair(2**16, 2**16)
try:
test_pair(2**52, 2**52)
except ValueError:
pass # long integers suffer from some imprecision at this size
try:
test_pair(-1, -1)
except ValueError:
pass # negative values not supported
return "Tests pass."
if __name__ == '__main__':
print(run_tests())
print("Benchmarking...")
i = 20000
print(round(timeit.timeit(run_tests, number=i), 5), "sec,", i, "iterations")