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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
(in-package :tim-judge)
(defparameter *solution-1*
(make-instance 'tim-solution
:solution-id 1
:solution-file "test/printaline.c"
:language :c
:solution-output "jail/1"
:problem-code "printaline"))
(defparameter *solution-2*
(make-instance 'tim-solution
:solution-id 2
:solution-file "test/printaline.py"
:language :python
:solution-output "jail/2"
:problem-code "printaline"))
(defparameter *solution-3*
(make-instance 'tim-solution
:solution-id 3
:solution-file "test/printaline.go"
:language :go
:solution-output "jail/3"
:problem-code "printaline"))
(defparameter *solution-4*
(make-instance 'tim-solution
:solution-id 4
:solution-file "test/printaline.pas"
:language :pascal
:solution-output "jail/4"
:problem-code "printaline"))
(defparameter *problem-1*
(make-instance 'tim-problem
:input-dir "test/"
:problem-code "printaline"
:problem-name "Print a Line"))
(defparameter *test-problem-set*
(list *problem-1*))
(defparameter *test-solution-set*
(list *solution-1* *solution-2*))
(defparameter *test-test-set-1*
(make-instance 'tim-test-set
:problem-code "printaline"
:solution-id 1
:from-test 1
:to-test 1))
(define-test language->compiler
(assert-equal "cpython" (language->compiler :python))
(assert-equal "gcc" (language->compiler :c) )
(assert-equal "g++" (language->compiler :c++))
(assert-equal "6g" (language->compiler :go))
(assert-equal "fpc" (language->compiler :pascal)))
(define-test language->interpreter
(assert-equal "python" (language->interpreter :python))
(assert-equal "" (language->interpreter :c))
(assert-equal "" (language->interpreter :c++))
(assert-equal "" (language->interpreter :go))
(assert-equal "" (language->interpreter :pascal)))
(define-test language->extension
(assert-equal "py" (language->extension :python))
(assert-equal "c" (language->extension :c))
(assert-equal "cpp" (language->extension :c++))
(assert-equal "go" (language->extension :go))
(assert-equal "pas" (language->extension :pascal)))
(define-test replace->extension
(assert-equal "hello.txt" (replace-extension "hello.old" "old" "txt"))
(assert-equal "odd.old" (replace-extension "odd.ttttt" "ttttt" "old")))
(define-test make-compile-helper
(assert-equal (concatenate 'string *working-dir* "compile-cpython.sh")
(make-compile-helper :python))
(assert-equal (concatenate 'string *working-dir* "compile-gcc.sh")
(make-compile-helper :c))
(assert-equal (concatenate 'string *working-dir* "compile-g++.sh")
(make-compile-helper :c++))
(assert-equal (concatenate 'string *working-dir* "compile-6g.sh")
(make-compile-helper :go))
(assert-equal (concatenate 'string *working-dir* "compile-fpc.sh")
(make-compile-helper :pascal)))
(define-test compile-solution
(assert-equal 0 (compile-solution *solution-1*))
(assert-equal 0 (compile-solution *solution-2*))
(assert-equal 0 (compile-solution *solution-3*))
(assert-equal 0 (compile-solution *solution-4*)))
(define-test compare-text
(assert-equal 0 (compare-text "main.lisp" "main.lisp"))
(assert-equal 1 (compare-text "main.lisp" "test.lisp")))
(define-test test-type->extension
(assert-equal "in" (test-type->extension :input))
(assert-equal "out" (test-type->extension :output))
(assert-equal "ans" (test-type->extension :answer)))
(define-test make-test-file
(assert-equal "1.in" (make-test-file :input 1))
(assert-equal "1.ans" (make-test-file :answer "1")))
(define-test make-test-output
(assert-equal "output/155_1.out" (make-test-output 155 1))
(assert-equal "output/52_10.out" (make-test-output 52 "10")))
(define-test make-run-test-command
(assert-equalp '("run-test.sh" "jail/1" "1" "test/" "output/1_1.out")
(make-run-test-command *problem-1*
*solution-1*)))
(define-test run-test
(assert-false nil (progn
(compile-solution *solution-1*)
(run-test *problem-1* *solution-1*)
(osicat:file-exists-p "output/1_1.out")))
(assert-false nil (progn
(compile-solution *solution-2*)
(run-test *problem-1* *solution-2*)
(osicat:file-exists-p "output/2_1.out"))))
(define-test run-test-set
(assert-equalp '((1 1)) (run-test-set *test-test-set-1*
:problem-set *test-problem-set*
:solution-set *test-solution-set*)))
(define-test problem-code->problem
(assert-equalp *problem-1* (problem-code->problem
"printaline" *test-problem-set*))
(assert-equal nil (problem-code->problem "-1" *test-problem-set*)))
(define-test solution-id->solution
(assert-equal (conf-solution-id *solution-1*)
(conf-solution-id
(solution-id->solution 1 *test-solution-set*)))
(assert-equal nil
(solution-id->solution 20202 *test-solution-set*)))
(define-test make-answer-file
(assert-equal "test/202.ans" (make-answer-file "test/" 202))
(assert-equal "/boot/arch/20.ans" (make-answer-file "/boot/arch/" 20)))
(define-test make-result-form
(assert-equalp '(1 1) (make-result-form 1 1))
(assert-equalp '(10 0) (make-result-form 10 0))
(assert-equalp '(20 -1) (make-result-form 20 -1)))
(define-test judge-result
(assert-equal 1 (progn
(compile-solution *solution-1*)
(run-test *problem-1* *solution-1*)
(judge-result *problem-1* *solution-1* 1))))
(define-test judge-text-compare
(assert-equal 1 (judge-text-compare "main.lisp" "main.lisp"))
(assert-equal 0 (judge-text-compare "main.lisp" "test.lisp")))
(defun test-tim-judge ()
(run-tests test-type->extension
language->compiler
language->interpreter
language->extension
replace->extension
problem-code->problem
solution-id->solution
make-compile-helper
make-answer-file
make-result-form
compile-solution
compare-text
judge-text-compare
judge-result
make-test-file
make-test-output
run-test
run-test-set
))
|