Description:
[grader] engine_spec: fix reg-ex new line problem, change test case for 1.5 sec submission (as the machine is a little faster) git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@150 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r39:7a9b64601b9d - - 3 files changed: 3 inserted, 3 deleted

@@ -1,21 +1,21
1 1 #include <stdio.h>
2 2 #include <stdlib.h>
3 3
4 4 int main()
5 5 {
6 6 int a,b;
7 7
8 8 int c=0;
9 9
10 10 scanf("%d %d",&a,&b);
11 11 printf("%d\n",a+b);
12 12
13 13 for(a=0; a<2; a++) {
14 - while(c<1150000000) {
14 + while(c<1550000000) {
15 15 c++;
16 16 b+=c;
17 17 }
18 18 }
19 19 exit(0);
20 20 }
21 21
@@ -139,142 +139,142
139 139 submission.should_receive(:compiler_message=).with(expected_compiler_message)
140 140 submission.should_receive(:save)
141 141
142 142 @engine.grade(submission)
143 143 end
144 144
145 145 protected
146 146
147 147 def create_normal_submission_mock_from_file(source_fname)
148 148 create_submission_from_file(1, @user_user1, @problem_test_normal, source_fname)
149 149 end
150 150
151 151 end
152 152
153 153 describe "A grader engine, when grading test requests" do
154 154
155 155 include GraderEngineHelperMethods
156 156
157 157 before(:each) do
158 158 @config = Grader::Configuration.get_instance
159 159 @engine = Grader::Engine.new(Grader::TestRequestRoomMaker.new,
160 160 Grader::TestRequestReporter.new)
161 161 init_sandbox
162 162 end
163 163
164 164 it "should report error if there is no problem template" do
165 165 problem = stub(Problem,
166 166 :id => 1, :name => 'nothing')
167 167 grader_should(:grade => 'test1_correct.c',
168 168 :on => problem,
169 169 :with => 'in1.txt',
170 170 :and_report => {
171 171 :graded_at= => nil,
172 172 :compiler_message= => '',
173 173 :grader_comment= => '',
174 174 :running_stat= => /template not found/,
175 175 :save => nil})
176 176 end
177 177
178 178 it "should run test request and produce output file" do
179 179 problem = stub(Problem,
180 180 :id => 1, :name => 'test_normal')
181 181 grader_should(:grade => 'test1_correct.c',
182 182 :on => problem,
183 183 :with => 'in1.txt',
184 184 :and_report => {
185 185 :graded_at= => nil,
186 186 :compiler_message= => '',
187 187 :grader_comment= => '',
188 188 :running_stat= => /0.0 sec./,
189 189 :output_file_name= => lambda { |fname|
190 190 File.exists?(fname).should be_true
191 191 },
192 192 :save => nil})
193 193 end
194 194
195 195 it "should clean up problem directory after running test request" do
196 196 problem = stub(Problem,
197 197 :id => 1, :name => 'test_normal')
198 198 grader_should(:grade => 'test1_correct.c',
199 199 :on => problem,
200 200 :with => 'in1.txt',
201 201 :and_report => {
202 202 :graded_at= => nil,
203 203 :compiler_message= => '',
204 204 :grader_comment= => '',
205 205 :running_stat= => nil,
206 206 :output_file_name= => nil,
207 207 :save => nil})
208 208 File.exists?(@config.user_result_dir + "/test_request/test_normal/test_cases/1/input-1.txt").should be_false
209 209 end
210 210
211 211 it "should compile test request with error and report compilation error" do
212 212 problem = stub(Problem,
213 213 :id => 1, :name => 'test_normal')
214 214 grader_should(:grade => 'test1_compile_error.c',
215 215 :on => problem,
216 216 :with => 'in1.txt',
217 217 :and_report => {
218 218 :graded_at= => nil,
219 219 :compiler_message= => /.+/,
220 220 :grader_comment= => /[Cc]ompil.*error/,
221 221 :running_stat= => '',
222 222 :save => nil})
223 223 end
224 224
225 225 it "should report exit status" do
226 226 problem = stub(Problem,
227 227 :id => 1, :name => 'test_normal')
228 228 grader_should(:grade => 'add_nonzero_exit_status.c',
229 229 :on => problem,
230 230 :with => 'in1.txt',
231 231 :and_report => {
232 232 :graded_at= => nil,
233 233 :compiler_message= => '',
234 234 :grader_comment= => '',
235 - :running_stat= => /[Ee]xit.*status.*10.*0.0 sec./,
235 + :running_stat= => /[Ee]xit.*status.*10.*0\.0 sec/m,
236 236 :output_file_name= => lambda { |fname|
237 237 File.exists?(fname).should be_true
238 238 },
239 239 :save => nil})
240 240 end
241 241
242 242 protected
243 243 def grader_should(args)
244 244 @user1 = stub(User,
245 245 :id => 1, :login => 'user1')
246 246
247 247 problem = args[:on]
248 248 input_file = @config.test_request_input_base_dir + "/" + args[:with]
249 249
250 250 submission =
251 251 create_submission_from_file(1, @user1, args[:on], args[:grade])
252 252
253 253 test_request = stub(TestRequest,
254 254 :id => 1,
255 255 :user => @user1,
256 256 :problem => problem,
257 257 :submission => submission,
258 258 :input_file_name => input_file,
259 259 :language => submission.language,
260 260 :problem_name => problem.name)
261 261
262 262 expectations = args[:and_report]
263 263
264 264 expectations.each do |key,val|
265 265 if val==nil
266 266 test_request.should_receive(key)
267 267 elsif val.class == Proc
268 268 test_request.should_receive(key) { |fname|
269 269 val.call(fname)
270 270 }
271 271 else
272 272 test_request.should_receive(key).with(val)
273 273 end
274 274 end
275 275
276 276 @engine.grade(test_request)
277 277 end
278 278
279 279 end
280 280
@@ -1,30 +1,30
1 1 module GraderEngineHelperMethods
2 2
3 3 def clear_sandbox
4 4 config = Grader::Configuration.get_instance
5 5 clear_cmd = "rm -rf #{config.test_sandbox_dir}/*"
6 6 system(clear_cmd)
7 7 end
8 8
9 9 def init_sandbox
10 10 config = Grader::Configuration.get_instance
11 11 clear_sandbox
12 - Dir.mkdir config.user_result_dir
12 + FileUtils.mkdir_p config.user_result_dir
13 13 cp_cmd = "cp -R #{config.test_data_dir}/ev #{config.test_sandbox_dir}"
14 14 system(cp_cmd)
15 15 end
16 16
17 17 def create_submission_from_file(id, user, problem,
18 18 source_fname, language=nil)
19 19
20 20 language = stub(Language, :name => 'c', :ext => 'c') if language==nil
21 21
22 22 config = Grader::Configuration.get_instance
23 23 source = File.open(config.test_data_dir + "/" + source_fname).read
24 24 stub(Submission,
25 25 :id => id, :user => user, :problem => problem,
26 26 :source => source, :language => language)
27 27 end
28 28
29 29 end
30 30
You need to be logged in to leave comments. Login now