diff --git a/std-script/grade b/std-script/grade new file mode 100755 --- /dev/null +++ b/std-script/grade @@ -0,0 +1,65 @@ +#!/usr/bin/ruby + +def char_comment(comment) + if comment =~ /[iI]ncorrect/ + '-' + elsif comment =~ /[Cc]orrect/ + 'P' + elsif comment =~ /[Tt]ime/ + 'T' + else + '?' + end +end + +problem_home = ENV['PROBLEM_HOME'] +require "#{problem_home}/script/test_dsl.rb" +load "#{problem_home}/test_cases/all_tests.cfg" +problem = Problem.get_instance + +if problem.well_formed? == false + puts "The problem specification is not well formed." + exit(127) +end + +all_score = 0 +all_comment = '' +(1..(problem.runs.length-1)).each do |k| + run = problem.runs[k] + run_score = 0 + run_comment = '' + run.tests.each do |test_num| + result_file_name = "#{test_num}/result" + if not File.exists?(result_file_name) + puts "Cannot find the file #{test_num}/result!" + exit(127) + end + + result_file = File.new(result_file_name, "r") + result_file_lines = result_file.readlines + run_score = run_score + result_file_lines[1].to_i + run_comment += char_comment(result_file_lines[0]) + result_file.close + end + + run_result_file = File.new("result-#{k}", "w") + run_result_file.write run_score + run_result_file.write "\n" + run_result_file.close + + run_comment_file = File.new("comment-#{k}", "w") + run_comment_file.write "#{run_comment}\n" + run_comment_file.close + + all_score = all_score + run_score + all_comment += run_comment +end + +result_file = File.new("result", "w") +result_file.write all_score +result_file.write "\n" +result_file.close + +comment_file = File.new("comment", "w") +comment_file.write "#{all_comment}\n" +comment_file.close