-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrading.py
More file actions
executable file
·61 lines (55 loc) · 2.04 KB
/
grading.py
File metadata and controls
executable file
·61 lines (55 loc) · 2.04 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
#!/usr/bin/env python
import os, time, sys
from os.path import isfile, join
import shutil
os.system('./build')
test_output = 'test_output'
tests = 'tests'
if len(sys.argv) == 2:
tests = sys.argv[1]
try:
shutil.rmtree(test_output)
except:
pass
os.mkdir(test_output)
for f in os.listdir(tests):
abs_f = join(tests, f)
if isfile(abs_f):
if f[len(f) - len('.input'):] == '.input':
fn = f[:len(f) - len('.input')]
print fn,
os.system('./master.py < ' + abs_f + \
' 2> ' + join(test_output, fn+'.err') +\
' > ' + join(test_output, fn+'.output'))
with open(join(test_output, fn+'.output')) as fi:
out = fi.read().strip().split('\n')
with open(join(tests, fn+'.output')) as fi:
std = fi.read().strip().split('\n')
result = True
out_index = 0
for s in std:
json = eval(s)
prev = None
for i in range(json['count']):
# check the number of lines in output
if out_index >= len(out):
result = False
break
# check if all the outputs are identical
if prev is not None and prev != out[out_index]:
result = False
prev = out[out_index]
# check if the output satisfies the requirement
out_data = set(out[out_index].split(','))
std_mandatory = set(json['mandatory'].split(','))
std_all = set(json['optional'].split(',')).union(std_mandatory)
if not out_data.issubset(std_all):
result = False
if not out_data.issuperset(std_mandatory):
result = False
out_index += 1
if result:
print 'correct'
else:
print 'wrong'
time.sleep(2)