diff --git a/import_problem b/import_problem --- a/import_problem +++ b/import_problem @@ -38,14 +38,22 @@ SCRIPT_DIR = File.dirname(__FILE__) # print usage -if ARGV.length < 3 +if ARGV.length < 4 puts < 1, :mem_limit => 16} process_options(options) # start working puts "creating directories" - system("mkdir #{problem}") system("mkdir #{problem}/script") system("mkdir #{problem}/test_cases") @@ -85,6 +92,15 @@ cfg_file.puts all_test_cfg.result cfg_file.close + +# copy check script +if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") + check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" +else + check_script_fname = check_script +end +system("cp #{check_script_fname} #{problem}/script/check") + # generating test_request directory puts "generating test_request template" FileUtils.mkdir_p("test_request/#{problem}/script") diff --git a/templates/check.integer b/templates/check.integer new file mode 100755 --- /dev/null +++ b/templates/check.integer @@ -0,0 +1,62 @@ +#!/usr/bin/ruby + +problem_home = ENV['PROBLEM_HOME'] +require "#{problem_home}/script/test_dsl.rb" + +if ARGV.length < 2 + puts "Usage: check []" + exit(0) +end + +language = ARGV[0] +test_num = ARGV[1].to_i +if ARGV.length >= 3 + output_file_name = ARGV[2] +else + output_file_name = "output.txt" +end + +load "#{problem_home}/test_cases/all_tests.cfg" +problem = Problem.get_instance + +output_file = File.new(output_file_name, "r") +answer_file = File.new("#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt") +result_file = File.new("check_result", "w") + +output_file_content = output_file.read +answer_file_content = answer_file.read + +report_correct = lambda { + result_file.write "Correct\n" + result_file.write problem.get_score(test_num) + result_file.write "\n" + result_file.close + exit(0) +} + +report_wrong = lambda { + result_file.write "Incorrect\n" + result_file.write "0\n" + result_file.close + exit(0) +} + +################## +# Your code here # +################## + +########### THIS IS FOR CHECKING INTEGER ########## +num_pattern = /^[0-9]*/ +if (output_file_content =~ num_pattern) == nil + report_wrong.call +end + +output_i = output_file_content.to_i +answer_i = answer_file_content.to_i + +if output_i == answer_i + report_correct.call +else + report_wrong.call +end + diff --git a/templates/check.text b/templates/check.text new file mode 100755 --- /dev/null +++ b/templates/check.text @@ -0,0 +1,64 @@ +#!/usr/bin/ruby + +problem_home = ENV['PROBLEM_HOME'] +require "#{problem_home}/script/test_dsl.rb" + +if ARGV.length < 2 + puts "Usage: check []" + exit(0) +end + +language = ARGV[0] +test_num = ARGV[1].to_i +if ARGV.length >= 3 + output_file_name = ARGV[2] +else + output_file_name = "output.txt" +end + +load "#{problem_home}/test_cases/all_tests.cfg" +problem = Problem.get_instance + +output_file = File.new(output_file_name, "r") +answer_file = File.new("#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt") +result_file = File.new("check_result", "w") + +output_file_content = output_file.read +answer_file_content = answer_file.read + +report_correct = lambda { + result_file.write "Correct\n" + result_file.write problem.get_score(test_num) + result_file.write "\n" + result_file.close + exit(0) +} + +report_wrong = lambda { + result_file.write "Incorrect\n" + result_file.write "0\n" + result_file.close + exit(0) +} + +################## +# Your code here # +################## + +########### THIS IS FOR CHECKING TEXT ########## + +# check visible text + +out_items = output_file_content.split +ans_items = answer_file_content.split + +if out_items.length != ans_items.length + report_wrong.call +else + out_items.length.times do |i| + if out_items[i]!=ans_items[i] + report_wrong.call + end + end + report_correct.call +end