-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
69 lines (57 loc) · 1.43 KB
/
tests.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
#!/usr/bin/env python
"""
Solutions to Project Euler Problems
http://projecteuler.net/
by Apalala <[email protected]>
(cc) Attribution-ShareAlike
http://creativecommons.org/licenses/by-sa/3.0/
"""
from pathlib import Path
from timeit import timeit
import sys
sys.path.insert(0, 'solutions')
def test_assertions_on():
try:
assert False
print('Please turn on assertions!')
sys.exit()
except AssertionError:
pass
def timed_test(name):
return timeit(
'test();run()',
'from ' + name + ' import test, run',
number=1
)
def main():
test_assertions_on()
total_time = 0
success_count = 0
failed = 0
modules = [p.stem for p in Path().glob('solutions/euler*.py')]
for name in modules:
print('%-40s ' % name, end='')
sys.stdout.flush()
try:
time = timed_test(name)
print(round(time, 3))
total_time += time
success_count += 1
except KeyboardInterrupt:
break
except ImportError as e:
print('untested', e)
except AssertionError as ae:
failed += 1
print('FAILED!')
except Exception as e:
failed += 1
print(e)
print()
print(
'total time for', success_count, 'problems,',
failed, 'failed,',
'is:', round(total_time, 3)
)
if __name__ == '__main__':
main()