forked from UPEISMCSCCC/kattis-grind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·49 lines (40 loc) · 1.46 KB
/
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
#!/usr/bin/env python3
import os
import sys
import argparse
ISON_WINDOWS = sys.platform == 'win32'
WRITER_NAME = 'type' if ISON_WINDOWS else 'cat'
parser = argparse.ArgumentParser(description='Runs Kattis problem through their test cases')
parser.add_argument('qid', metavar='ID', type=str, help='id of problem to fetch')
args = parser.parse_args()
qid = args.qid
if qid == None:
qid = input('Enter ID: ')
PROBLEMS_PATH = './problems/'
PROBLEM_PATH = PROBLEMS_PATH + qid
qdir = os.path.join(PROBLEM_PATH)
qext = 'z'
while qext != 'c' and qext != 'p':
qext = input('Which language (py/cpp): ')
qext = qext[:1].lower()
if qext == 'p':
EXE_NAME = '%s/_%s.py'%(qdir,qid)
else:
EXE_NAME = '%s/_%s.exe'%(qdir,qid) if ISON_WINDOWS else '%s/_%s'%(qdir,qid)
isinfile_inqdir = lambda name: name.startswith("input") and os.path.isfile(os.path.join(qdir,name))
input_files = list(filter(isinfile_inqdir, os.listdir(qdir)))
ilen = len(input_files)
os.system('g++ "' + qdir + '/_' + qid + '.cpp" -o ' + EXE_NAME)
for i in range(ilen):
print('TEST CASE ' + str(i+1))
output = os.popen('%s \"'%WRITER_NAME + os.path.join(qdir,'input' + str(i+1)) + '\" | %s'%EXE_NAME).read().rstrip()
print('OUTPUT:')
print(output)
with open(qdir + '/output' + str(i+1)) as expected:
content = expected.read().rstrip()
print('EXPECTED OUTPUT:')
print(content)
if content==output:
print('PASSED')
else:
print('FAILED')