diff --git a/import_problem b/import_problem --- a/import_problem +++ b/import_problem @@ -6,6 +6,7 @@ require 'erb' require 'fileutils' +require File.join(File.dirname(__FILE__),'lib/import_helper') def input_filename(dir,i) "#{dir}/input-#{i}.txt" @@ -15,9 +16,16 @@ "#{dir}/answer-#{i}.txt" end -def copy_testcase(importing_test_dir,dir,i) - system("cp #{importing_test_dir}/#{i}.in #{input_filename(dir,i)}") - system("cp #{importing_test_dir}/#{i}.sol #{answer_filename(dir,i)}") +def build_testrun_info_from_dir(num_testruns,importing_test_dir) + filenames = Dir["#{importing_test_dir}/*.in"].collect do |filename| + File.basename((/(.*)\.in/.match(filename))[1]) + end + build_testrun_info(num_testruns,filenames) +end + +def copy_testcase(importing_test_dir,fname,dir,i) + system("cp #{importing_test_dir}/#{fname}.in #{input_filename(dir,i)}") + system("cp #{importing_test_dir}/#{fname}.sol #{answer_filename(dir,i)}") end def process_options(options) @@ -43,7 +51,7 @@ using: import_problem name dir num check [options] where: name = problem_name (put '-' (dash) to use dir name) dir = importing testcase directory - num = number of testcases + num = number of testruns check = check script, which can be 'integer', 'text' (for standard script), path_to_your_script, or @@ -66,11 +74,13 @@ problem = ARGV[0] testcase_dir = ARGV[1] problem = File.basename(testcase_dir) if problem=="-" -num_testcases = ARGV[2].to_i +num_testruns = ARGV[2].to_i check_script = ARGV[3] options = {:time_limit => 1, :mem_limit => 16} process_options(options) +testrun_info = build_testrun_info_from_dir(num_testruns, testcase_dir) + # start working puts "creating directories" @@ -81,12 +91,26 @@ puts "copying testcases" -1.upto(num_testcases) do |i| - system("mkdir #{problem}/test_cases/#{i}") - copy_testcase("#{testcase_dir}","#{problem}/test_cases/#{i}",i) +tr_num = 0 + +num_testcases = 0 + +testrun_info.each do |testrun| + tr_num += 1 + puts "testrun: #{tr_num}" + + testrun.each do |testcase_info| + testcase_num, testcase_fname = testcase_info + + puts "copy #{testcase_fname} to #{testcase_num}" + + system("mkdir #{problem}/test_cases/#{testcase_num}") + copy_testcase("#{testcase_dir}",testcase_fname,"#{problem}/test_cases/#{testcase_num}",testcase_num) + + num_testcases += 1 + end end - # generating all_tests.cfg puts "generating testcase config file" diff --git a/lib/import_helper.rb b/lib/import_helper.rb new file mode 100644 --- /dev/null +++ b/lib/import_helper.rb @@ -0,0 +1,28 @@ + +def filter_filename_for_testrun(testrun, filename_list) + l = [] + regex = Regexp.new("^(#{testrun}[a-z]*|#{testrun}-.*)$") + filename_list.each do |filename| + if regex.match(filename) + l << filename + end + end + l +end + +def build_testrun_info(num_testruns, input_filename_list) + info = [] + num_testcases = 0 + num_testruns.times do |i| + r = i+1 + testrun_info = [] + filenames = filter_filename_for_testrun(r, input_filename_list) + filenames.each do |fname| + num_testcases += 1 + testrun_info << [num_testcases,fname] + end + info << testrun_info + end + info +end + diff --git a/templates/all_tests.cfg.erb b/templates/all_tests.cfg.erb --- a/templates/all_tests.cfg.erb +++ b/templates/all_tests.cfg.erb @@ -1,13 +1,20 @@ problem do num_tests <%= num_testcases %> - full_score <%= num_testcases*10 %> + full_score <%= num_testruns*10 %> time_limit_each <%= options[:time_limit] %> mem_limit_each <%= options[:mem_limit] %> score_each 10 -<% 1.upto(num_testcases) do |i| %> - run <%= i %> do - tests <%= i %> +<% tr_num = 0 %> +<% testrun_info.each do |testrun| %> + <% tr_num += 1 %> + run <%= tr_num %> do + tests <%= (testrun.collect {|testcase| testcase[0]}).join(", ") %> + <% if testrun.length==1 %> + score 10 + <% else %> + scores 10 <% (testrun.length-1).times do %>,0 <% end %> + <% end %> end <% end %> end diff --git a/test/import_helper_test.rb b/test/import_helper_test.rb new file mode 100644 --- /dev/null +++ b/test/import_helper_test.rb @@ -0,0 +1,40 @@ +require 'test/unit' +require 'rubygems' +require 'mocha' + +require File.join(File.dirname(__FILE__),'../lib/import_helper') + +class ImportHelperTest < Test::Unit::TestCase + + def setup + end + + def teardown + end + + def test_build_only_singleton_testruns + testrun_info = build_testrun_info(3,['1','2','3']) + assert_equal [[[1,'1']],[[2,'2']],[[3,'3']]], testrun_info, 'should build singleton testruns' + end + + def test_build_only_singleton_testruns2 + testrun_info = build_testrun_info(4,['1','2','3','4']) + assert_equal [[[1,'1']],[[2,'2']],[[3,'3']],[[4,'4']]], testrun_info, 'should build singleton testruns' + end + + def test_build_testruns_when_testcases_defined_by_appending_alphabets + testrun_info = build_testrun_info(4,['1a','1b','2','3a','3b','4']) + assert_equal [[[1,'1a'],[2,'1b']], + [[3,'2']], + [[4,'3a'],[5,'3b']], + [[6,'4']]], testrun_info + end + + def test_build_testruns_when_testcases_defined_by_appending_dashed_numbers + testrun_info = build_testrun_info(4,['1-1','1-2','2','3-1','3-2','4']) + assert_equal [[[1,'1-1'],[2,'1-2']], + [[3,'2']], + [[4,'3-1'],[5,'3-2']], + [[6,'4']]], testrun_info + end +end