-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_judge.py
More file actions
75 lines (67 loc) · 2.44 KB
/
run_judge.py
File metadata and controls
75 lines (67 loc) · 2.44 KB
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
70
71
72
73
74
import os
import json
import subprocess
from filecmp import cmp as fcmp
data_dir='data'
compile_script='build.sh'
run_script='run.sh'
clean_script='clean.sh'
def printRet(detail=True):
def decorator(func):
def wrapper(*args, **kw):
if detail:
print("\033[36m{}\033[0m".format('call: {}'.format(func.__name__)))
ret,val=func(*args, **kw)
if val!='':
if ret==0:
print("\033[37m{}\033[0m".format(val))
else:
print("\033[31m{}\033[0m".format('ret code: '+str(ret)))
print("\033[37m{}\033[0m".format(val))
quit()
return wrapper
return decorator
@printRet(True)
def compile_project():
return subprocess.getstatusoutput('sh {}'.format(compile_script))
@printRet(False)
def run(input_path):
return subprocess.getstatusoutput('sh {} <{} > tmp.out'.format(run_script,input_path))
@printRet(False)
def clean():
subprocess.getstatusoutput('rm tmp.out')
return subprocess.getstatusoutput('sh {}'.format(clean_script))
def main():
if not os.path.exists(data_dir):
print("\033[31m{}\033[0m".format('data set not find!'))
exit(127)
with open('{}/config.json'.format(data_dir),'r')as f:
testInfo=json.load(f)
compile_project()
errorCase=[]
for info in testInfo:
fail_point=None
print('test for {}'.format(info['name']))
for point in info['point']:
file_path='{}/{}/{}'.format(data_dir,info['name'],point)
if os.path.exists(file_path+'.in') and os.path.exists(file_path+'.out'):
run(file_path+'.in')
try:
result=fcmp(file_path+'.out','tmp.out')
except:
result=False
if not result:
errorCase.append((info['name']))
fail_point=point
break
else:
print("\033[31m{}\033[0m".format('data set is broken at {}!'.format(file_path)))
exit(127)
clean()
if fail_point==None:
print("\033[36m{}\033[0m".format('success in {}'.format(info['name'])))
else:
print("\033[31m{}\033[0m".format('case {} fail at {}'.format(info['name'],fail_point)))
print("\033[36m{}\033[0m".format('pass case {}/{}'.format(len(errorCase),len(testInfo))))
if __name__=='__main__':
main()