-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·43 lines (36 loc) · 976 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
#!/usr/bin/env python3
import os
import time
import subprocess
import unittest
class TestSolutions(unittest.TestCase):
pass
def make_test_case(num, answer):
def test_case(self):
start = time.time()
result = subprocess.run(
'bin/' + num,
stdout=subprocess.PIPE,
encoding='utf-8',
timeout=10
)
duration = time.time() - start
self.assertEqual(
result.returncode,
0
)
self.assertEqual(
result.stdout.strip(),
answer
)
print(f"{num}: {int(duration * 1000)} ms")
return test_case
binfiles = sorted(os.listdir('bin/'))
answers = [""] + open('answers.txt', 'r').read().split('\n')
for f in binfiles:
if f == '000': # This is the scratch file
continue
a = answers[int(f)]
setattr(TestSolutions, "test_" + f, make_test_case(f, a))
if __name__ == "__main__":
unittest.main()