Description:
[grader] fixed the case when result file is ill-formatted
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@130 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r34:4907486f53b2 - - 2 files changed: 10 inserted, 0 deleted
@@ -39,27 +39,31 | |||
|
39 | 39 | def report(sub,test_result_dir) |
|
40 | 40 | save_result(sub,read_result(test_result_dir)) |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def report_error(sub,msg) |
|
44 | 44 | save_result(sub,{:points => 0, |
|
45 | 45 | :comment => "Grading error: #{msg}" }) |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | protected |
|
49 | 49 | def read_result(test_result_dir) |
|
50 | 50 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
51 | + if FileTest.exist?(cmp_msg_fname) | |
|
51 | 52 | cmp_file = File.open(cmp_msg_fname) |
|
52 | 53 | cmp_msg = cmp_file.read |
|
53 | 54 | cmp_file.close |
|
55 | + else | |
|
56 | + cmp_msg = "" | |
|
57 | + end | |
|
54 | 58 | |
|
55 | 59 | result_fname = "#{test_result_dir}/result" |
|
56 | 60 | comment_fname = "#{test_result_dir}/comment" |
|
57 | 61 | if FileTest.exist?(result_fname) |
|
58 | 62 | comment = "" |
|
59 | 63 | begin |
|
60 | 64 | result_file = File.open(result_fname) |
|
61 | 65 | result = result_file.readline.to_i |
|
62 | 66 | result_file.close |
|
63 | 67 | rescue |
|
64 | 68 | result = 0 |
|
65 | 69 | comment = "error reading result file." |
@@ -47,27 +47,33 | |||
|
47 | 47 | run_score = 0 |
|
48 | 48 | run_comment = '' |
|
49 | 49 | run_comment_short = '' |
|
50 | 50 | run.tests.each do |test_num| |
|
51 | 51 | result_file_name = "#{test_num}/result" |
|
52 | 52 | if not File.exists?(result_file_name) |
|
53 | 53 | run_comment += "result file for test #{test_num} not found\n" |
|
54 | 54 | run_comment_short += RUN_ERROR_MARK |
|
55 | 55 | log "Cannot find the file #{test_num}/result!" |
|
56 | 56 | else |
|
57 | 57 | result_file = File.new(result_file_name, "r") |
|
58 | 58 | result_file_lines = result_file.readlines |
|
59 | + if result_file_lines.length>=2 | |
|
59 | 60 | run_score = run_score + result_file_lines[1].to_i |
|
60 | 61 | run_comment += result_file_lines[0] |
|
61 | 62 | run_comment_short += char_comment(result_file_lines[0]) |
|
63 | + else | |
|
64 | + run_comment += "result file for test #{test_num} error\n" | |
|
65 | + run_comment_short += RUN_ERROR_MARK | |
|
66 | + log "Error in #{test_num}/result!" | |
|
67 | + end | |
|
62 | 68 | result_file.close |
|
63 | 69 | end |
|
64 | 70 | end |
|
65 | 71 | |
|
66 | 72 | # find total score for this run |
|
67 | 73 | run_total_score = 0 |
|
68 | 74 | problem = Problem.get_instance |
|
69 | 75 | run.tests.each { |test_num| run_total_score += problem.get_score(test_num) } |
|
70 | 76 | |
|
71 | 77 | if run_total_score!=run_score # fail in some test cases, fail the run |
|
72 | 78 | run_score = 0 |
|
73 | 79 | end |
You need to be logged in to leave comments.
Login now