Description:
[grader] import script now support raw with testruns
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@267 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
r63:031546561018 - - 4 files changed: 112 inserted, 13 deleted
@@ -0,0 +1,28 | |||
|
1 | + | |
|
2 | + def filter_filename_for_testrun(testrun, filename_list) | |
|
3 | + l = [] | |
|
4 | + regex = Regexp.new("^(#{testrun}[a-z]*|#{testrun}-.*)$") | |
|
5 | + filename_list.each do |filename| | |
|
6 | + if regex.match(filename) | |
|
7 | + l << filename | |
|
8 | + end | |
|
9 | + end | |
|
10 | + l | |
|
11 | + end | |
|
12 | + | |
|
13 | + def build_testrun_info(num_testruns, input_filename_list) | |
|
14 | + info = [] | |
|
15 | + num_testcases = 0 | |
|
16 | + num_testruns.times do |i| | |
|
17 | + r = i+1 | |
|
18 | + testrun_info = [] | |
|
19 | + filenames = filter_filename_for_testrun(r, input_filename_list) | |
|
20 | + filenames.each do |fname| | |
|
21 | + num_testcases += 1 | |
|
22 | + testrun_info << [num_testcases,fname] | |
|
23 | + end | |
|
24 | + info << testrun_info | |
|
25 | + end | |
|
26 | + info | |
|
27 | + end | |
|
28 | + |
@@ -0,0 +1,40 | |||
|
1 | + require 'test/unit' | |
|
2 | + require 'rubygems' | |
|
3 | + require 'mocha' | |
|
4 | + | |
|
5 | + require File.join(File.dirname(__FILE__),'../lib/import_helper') | |
|
6 | + | |
|
7 | + class ImportHelperTest < Test::Unit::TestCase | |
|
8 | + | |
|
9 | + def setup | |
|
10 | + end | |
|
11 | + | |
|
12 | + def teardown | |
|
13 | + end | |
|
14 | + | |
|
15 | + def test_build_only_singleton_testruns | |
|
16 | + testrun_info = build_testrun_info(3,['1','2','3']) | |
|
17 | + assert_equal [[[1,'1']],[[2,'2']],[[3,'3']]], testrun_info, 'should build singleton testruns' | |
|
18 | + end | |
|
19 | + | |
|
20 | + def test_build_only_singleton_testruns2 | |
|
21 | + testrun_info = build_testrun_info(4,['1','2','3','4']) | |
|
22 | + assert_equal [[[1,'1']],[[2,'2']],[[3,'3']],[[4,'4']]], testrun_info, 'should build singleton testruns' | |
|
23 | + end | |
|
24 | + | |
|
25 | + def test_build_testruns_when_testcases_defined_by_appending_alphabets | |
|
26 | + testrun_info = build_testrun_info(4,['1a','1b','2','3a','3b','4']) | |
|
27 | + assert_equal [[[1,'1a'],[2,'1b']], | |
|
28 | + [[3,'2']], | |
|
29 | + [[4,'3a'],[5,'3b']], | |
|
30 | + [[6,'4']]], testrun_info | |
|
31 | + end | |
|
32 | + | |
|
33 | + def test_build_testruns_when_testcases_defined_by_appending_dashed_numbers | |
|
34 | + testrun_info = build_testrun_info(4,['1-1','1-2','2','3-1','3-2','4']) | |
|
35 | + assert_equal [[[1,'1-1'],[2,'1-2']], | |
|
36 | + [[3,'2']], | |
|
37 | + [[4,'3-1'],[5,'3-2']], | |
|
38 | + [[6,'4']]], testrun_info | |
|
39 | + end | |
|
40 | + end |
@@ -3,24 +3,32 | |||
|
3 | 3 | # import_problem: |
|
4 | 4 | # * creates a directory for a problem in the current directory, |
|
5 | 5 | # * copy testdata in the old format and create standard testcase config file |
|
6 | 6 | |
|
7 | 7 | require 'erb' |
|
8 | 8 | require 'fileutils' |
|
9 | + require File.join(File.dirname(__FILE__),'lib/import_helper') | |
|
9 | 10 | |
|
10 | 11 | def input_filename(dir,i) |
|
11 | 12 | "#{dir}/input-#{i}.txt" |
|
12 | 13 | end |
|
13 | 14 | |
|
14 | 15 | def answer_filename(dir,i) |
|
15 | 16 | "#{dir}/answer-#{i}.txt" |
|
16 | 17 | end |
|
17 | 18 | |
|
18 | - def copy_testcase(importing_test_dir,dir,i) | |
|
19 | - system("cp #{importing_test_dir}/#{i}.in #{input_filename(dir,i)}") | |
|
20 | - system("cp #{importing_test_dir}/#{i}.sol #{answer_filename(dir,i)}") | |
|
19 | + def build_testrun_info_from_dir(num_testruns,importing_test_dir) | |
|
20 | + filenames = Dir["#{importing_test_dir}/*.in"].collect do |filename| | |
|
21 | + File.basename((/(.*)\.in/.match(filename))[1]) | |
|
22 | + end | |
|
23 | + build_testrun_info(num_testruns,filenames) | |
|
24 | + end | |
|
25 | + | |
|
26 | + def copy_testcase(importing_test_dir,fname,dir,i) | |
|
27 | + system("cp #{importing_test_dir}/#{fname}.in #{input_filename(dir,i)}") | |
|
28 | + system("cp #{importing_test_dir}/#{fname}.sol #{answer_filename(dir,i)}") | |
|
21 | 29 | end |
|
22 | 30 | |
|
23 | 31 | def process_options(options) |
|
24 | 32 | i = 4 |
|
25 | 33 | while i<ARGV.length |
|
26 | 34 | if ARGV[i]=='-t' |
@@ -40,13 +48,13 | |||
|
40 | 48 | # print usage |
|
41 | 49 | if (ARGV.length < 4) or (ARGV[3][0,1]=="-") |
|
42 | 50 | puts <<USAGE |
|
43 | 51 | using: import_problem name dir num check [options] |
|
44 | 52 | where: name = problem_name (put '-' (dash) to use dir name) |
|
45 | 53 | dir = importing testcase directory |
|
46 |
- num = number of test |
|
|
54 | + num = number of testruns | |
|
47 | 55 | check = check script, which can be |
|
48 | 56 | 'integer', 'text' (for standard script), |
|
49 | 57 | path_to_your_script, or |
|
50 | 58 | 'wrapper:(path_to_your_wrapped_script)' |
|
51 | 59 | options: -t time-limit (in seconds) |
|
52 | 60 | -m memory-limit (in megabytes) |
@@ -63,33 +71,49 | |||
|
63 | 71 | end |
|
64 | 72 | |
|
65 | 73 | # processing arguments |
|
66 | 74 | problem = ARGV[0] |
|
67 | 75 | testcase_dir = ARGV[1] |
|
68 | 76 | problem = File.basename(testcase_dir) if problem=="-" |
|
69 |
- num_test |
|
|
77 | + num_testruns = ARGV[2].to_i | |
|
70 | 78 | check_script = ARGV[3] |
|
71 | 79 | options = {:time_limit => 1, :mem_limit => 16} |
|
72 | 80 | process_options(options) |
|
73 | 81 | |
|
82 | + testrun_info = build_testrun_info_from_dir(num_testruns, testcase_dir) | |
|
83 | + | |
|
74 | 84 | # start working |
|
75 | 85 | puts "creating directories" |
|
76 | 86 | |
|
77 | 87 | system("mkdir #{problem}") |
|
78 | 88 | system("mkdir #{problem}/script") |
|
79 | 89 | system("mkdir #{problem}/test_cases") |
|
80 | 90 | #system("cp #{GRADER_DIR}/std-script/* #{problem}/script") |
|
81 | 91 | |
|
82 | 92 | puts "copying testcases" |
|
83 | 93 | |
|
84 | - 1.upto(num_testcases) do |i| | |
|
85 | - system("mkdir #{problem}/test_cases/#{i}") | |
|
86 | - copy_testcase("#{testcase_dir}","#{problem}/test_cases/#{i}",i) | |
|
94 | + tr_num = 0 | |
|
95 | + | |
|
96 | + num_testcases = 0 | |
|
97 | + | |
|
98 | + testrun_info.each do |testrun| | |
|
99 | + tr_num += 1 | |
|
100 | + puts "testrun: #{tr_num}" | |
|
101 | + | |
|
102 | + testrun.each do |testcase_info| | |
|
103 | + testcase_num, testcase_fname = testcase_info | |
|
104 | + | |
|
105 | + puts "copy #{testcase_fname} to #{testcase_num}" | |
|
106 | + | |
|
107 | + system("mkdir #{problem}/test_cases/#{testcase_num}") | |
|
108 | + copy_testcase("#{testcase_dir}",testcase_fname,"#{problem}/test_cases/#{testcase_num}",testcase_num) | |
|
109 | + | |
|
110 | + num_testcases += 1 | |
|
111 | + end | |
|
87 | 112 | end |
|
88 | 113 | |
|
89 | - | |
|
90 | 114 | # generating all_tests.cfg |
|
91 | 115 | puts "generating testcase config file" |
|
92 | 116 | |
|
93 | 117 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read |
|
94 | 118 | all_test_cfg = ERB.new(template) |
|
95 | 119 |
@@ -1,13 +1,20 | |||
|
1 | 1 | problem do |
|
2 | 2 | num_tests <%= num_testcases %> |
|
3 |
- full_score <%= num_test |
|
|
3 | + full_score <%= num_testruns*10 %> | |
|
4 | 4 | time_limit_each <%= options[:time_limit] %> |
|
5 | 5 | mem_limit_each <%= options[:mem_limit] %> |
|
6 | 6 | score_each 10 |
|
7 | 7 | |
|
8 | - <% 1.upto(num_testcases) do |i| %> | |
|
9 | - run <%= i %> do | |
|
10 | - tests <%= i %> | |
|
8 | + <% tr_num = 0 %> | |
|
9 | + <% testrun_info.each do |testrun| %> | |
|
10 | + <% tr_num += 1 %> | |
|
11 | + run <%= tr_num %> do | |
|
12 | + tests <%= (testrun.collect {|testcase| testcase[0]}).join(", ") %> | |
|
13 | + <% if testrun.length==1 %> | |
|
14 | + score 10 | |
|
15 | + <% else %> | |
|
16 | + scores 10 <% (testrun.length-1).times do %>,0 <% end %> | |
|
17 | + <% end %> | |
|
11 | 18 | end |
|
12 | 19 | <% end %> |
|
13 | 20 | end |
You need to be logged in to leave comments.
Login now