-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck
More file actions
executable file
·106 lines (87 loc) · 2.61 KB
/
check
File metadata and controls
executable file
·106 lines (87 loc) · 2.61 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python3
import os
import gzip
import pickle
from autograder import cprint
from autograder import colored
# max score
SCORE = 35
# creates grading and grading/test-output directories
def start():
os.system('clear')
os.system('rm -rf ' + os.path.join('grading'))
os.system('rm -rf ' + os.path.join('grading', 'test-output'))
os.system('mkdir ' + os.path.join('grading'))
os.system('mkdir ' + os.path.join('grading', 'test-output'))
# creates an output file
def create(name, data):
if not os.path.exists(os.path.join('grading', name)):
f = open(os.path.join('grading', name), 'w')
f.write(data)
f.close()
# executes a test
def execute(name):
test = os.path.join('grading', name + '.vp')
testout = os.path.join('grading', '.tmp.s')
os.system('./run ' + test + ' >> grading/.tmp 2>&1')
testout = open('grading/.tmp', 'r')
testresult = testout.read().strip()
testout.close()
return testresult
# copy result
def copy(name, data):
f = open('grading/test-output/' + name + '.vp.out', 'w')
f.write(data)
f.close()
# calls diff
def diff(name):
cmd = 'diff grading/%s.vp.out grading/test-output/%s.vp.out' % (name, name)
cmd += ' > grading/test-output/%s.diff' % name
os.system(cmd)
# clear temp files
def clear():
os.system('rm -rf grading/.tmp')
os.system('rm -rf grading/.tmp.s')
# main script
def main():
f = gzip.open(os.path.join('autograder', 'data.pkl.gz'), 'rb')
data = pickle.load(f)
f.close()
start()
print('')
cprint(' Autograder', color='blue')
print('')
print('')
os.system('./gradlew clean build > /dev/null 2>&1')
grade = 0
for sample in data:
# unpack test data
input, output, name = sample
# create test input
create(name + '.vp', input)
# create test expected result
create(name + '.vp.out', output)
# run test
uresult = execute(name)
# compare
if uresult != output:
copy(name, uresult)
diff(name)
info = colored('-%d' % 1, 'red')
info += colored('(%s)' % name, 'cyan').center(30, ' ')
print(info)
else:
grade += 1
info = colored('+%d' % 1, 'green')
info += colored('(%s)' % name, 'cyan').center(30, ' ')
print(info)
# clear output
clear()
print('\n')
cprint('=> You got a score of %d out of %d.' % (grade, SCORE), color='yellow')
# save score
f = open('grading/SCORE', 'w')
f.write('%d' % grade)
f.close()
if __name__ == '__main__':
main()