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 |
@@ -1,113 +1,137 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | # import_problem: |
|
3 | # import_problem: |
|
4 | # * creates a directory for a problem in the current directory, |
|
4 | # * creates a directory for a problem in the current directory, |
|
5 | # * copy testdata in the old format and create standard testcase config file |
|
5 | # * copy testdata in the old format and create standard testcase config file |
|
6 |
|
6 | ||
|
7 | require 'erb' |
|
7 | require 'erb' |
|
8 | require 'fileutils' |
|
8 | require 'fileutils' |
|
|
9 | + require File.join(File.dirname(__FILE__),'lib/import_helper') | ||
|
9 |
|
10 | ||
|
10 | def input_filename(dir,i) |
|
11 | def input_filename(dir,i) |
|
11 | "#{dir}/input-#{i}.txt" |
|
12 | "#{dir}/input-#{i}.txt" |
|
12 | end |
|
13 | end |
|
13 |
|
14 | ||
|
14 | def answer_filename(dir,i) |
|
15 | def answer_filename(dir,i) |
|
15 | "#{dir}/answer-#{i}.txt" |
|
16 | "#{dir}/answer-#{i}.txt" |
|
16 | end |
|
17 | end |
|
17 |
|
18 | ||
|
18 | - def copy_testcase(importing_test_dir,dir,i) |
|
19 | + def build_testrun_info_from_dir(num_testruns,importing_test_dir) |
|
19 | - system("cp #{importing_test_dir}/#{i}.in #{input_filename(dir,i)}") |
|
20 | + filenames = Dir["#{importing_test_dir}/*.in"].collect do |filename| |
|
20 | - system("cp #{importing_test_dir}/#{i}.sol #{answer_filename(dir,i)}") |
|
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 | end |
|
29 | end |
|
22 |
|
30 | ||
|
23 | def process_options(options) |
|
31 | def process_options(options) |
|
24 | i = 4 |
|
32 | i = 4 |
|
25 | while i<ARGV.length |
|
33 | while i<ARGV.length |
|
26 | if ARGV[i]=='-t' |
|
34 | if ARGV[i]=='-t' |
|
27 | options[:time_limit] = ARGV[i+1].to_f if ARGV.length>i+1 |
|
35 | options[:time_limit] = ARGV[i+1].to_f if ARGV.length>i+1 |
|
28 | i += 1 |
|
36 | i += 1 |
|
29 | end |
|
37 | end |
|
30 | if ARGV[i]=='-m' |
|
38 | if ARGV[i]=='-m' |
|
31 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
39 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
32 | i += 1 |
|
40 | i += 1 |
|
33 | end |
|
41 | end |
|
34 | i += 1 |
|
42 | i += 1 |
|
35 | end |
|
43 | end |
|
36 | end |
|
44 | end |
|
37 |
|
45 | ||
|
38 | SCRIPT_DIR = File.dirname(__FILE__) |
|
46 | SCRIPT_DIR = File.dirname(__FILE__) |
|
39 |
|
47 | ||
|
40 | # print usage |
|
48 | # print usage |
|
41 | if (ARGV.length < 4) or (ARGV[3][0,1]=="-") |
|
49 | if (ARGV.length < 4) or (ARGV[3][0,1]=="-") |
|
42 | puts <<USAGE |
|
50 | puts <<USAGE |
|
43 | using: import_problem name dir num check [options] |
|
51 | using: import_problem name dir num check [options] |
|
44 | where: name = problem_name (put '-' (dash) to use dir name) |
|
52 | where: name = problem_name (put '-' (dash) to use dir name) |
|
45 | dir = importing testcase directory |
|
53 | dir = importing testcase directory |
|
46 |
- num = number of test |
|
54 | + num = number of testruns |
|
47 | check = check script, which can be |
|
55 | check = check script, which can be |
|
48 | 'integer', 'text' (for standard script), |
|
56 | 'integer', 'text' (for standard script), |
|
49 | path_to_your_script, or |
|
57 | path_to_your_script, or |
|
50 | 'wrapper:(path_to_your_wrapped_script)' |
|
58 | 'wrapper:(path_to_your_wrapped_script)' |
|
51 | options: -t time-limit (in seconds) |
|
59 | options: -t time-limit (in seconds) |
|
52 | -m memory-limit (in megabytes) |
|
60 | -m memory-limit (in megabytes) |
|
53 | What it does: |
|
61 | What it does: |
|
54 | * creates a directory for a problem in the current directory, |
|
62 | * creates a directory for a problem in the current directory, |
|
55 | * copies testdata in the old format and create standard testcase config file |
|
63 | * copies testdata in the old format and create standard testcase config file |
|
56 | * copies a check script for grading |
|
64 | * copies a check script for grading |
|
57 | * creates a test_request template in the current directory + '/test_request' |
|
65 | * creates a test_request template in the current directory + '/test_request' |
|
58 |
|
66 | ||
|
59 | For wrapped checked script see comment in templates/check_wrapper for |
|
67 | For wrapped checked script see comment in templates/check_wrapper for |
|
60 | information. |
|
68 | information. |
|
61 | USAGE |
|
69 | USAGE |
|
62 | exit(127) |
|
70 | exit(127) |
|
63 | end |
|
71 | end |
|
64 |
|
72 | ||
|
65 | # processing arguments |
|
73 | # processing arguments |
|
66 | problem = ARGV[0] |
|
74 | problem = ARGV[0] |
|
67 | testcase_dir = ARGV[1] |
|
75 | testcase_dir = ARGV[1] |
|
68 | problem = File.basename(testcase_dir) if problem=="-" |
|
76 | problem = File.basename(testcase_dir) if problem=="-" |
|
69 |
- num_test |
|
77 | + num_testruns = ARGV[2].to_i |
|
70 | check_script = ARGV[3] |
|
78 | check_script = ARGV[3] |
|
71 | options = {:time_limit => 1, :mem_limit => 16} |
|
79 | options = {:time_limit => 1, :mem_limit => 16} |
|
72 | process_options(options) |
|
80 | process_options(options) |
|
73 |
|
81 | ||
|
|
82 | + testrun_info = build_testrun_info_from_dir(num_testruns, testcase_dir) | ||
|
|
83 | + | ||
|
74 | # start working |
|
84 | # start working |
|
75 | puts "creating directories" |
|
85 | puts "creating directories" |
|
76 |
|
86 | ||
|
77 | system("mkdir #{problem}") |
|
87 | system("mkdir #{problem}") |
|
78 | system("mkdir #{problem}/script") |
|
88 | system("mkdir #{problem}/script") |
|
79 | system("mkdir #{problem}/test_cases") |
|
89 | system("mkdir #{problem}/test_cases") |
|
80 | #system("cp #{GRADER_DIR}/std-script/* #{problem}/script") |
|
90 | #system("cp #{GRADER_DIR}/std-script/* #{problem}/script") |
|
81 |
|
91 | ||
|
82 | puts "copying testcases" |
|
92 | puts "copying testcases" |
|
83 |
|
93 | ||
|
84 | - 1.upto(num_testcases) do |i| |
|
94 | + tr_num = 0 |
|
85 | - system("mkdir #{problem}/test_cases/#{i}") |
|
95 | + |
|
86 | - copy_testcase("#{testcase_dir}","#{problem}/test_cases/#{i}",i) |
|
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 | end |
|
112 | end |
|
88 |
|
113 | ||
|
89 | - |
|
||
|
90 | # generating all_tests.cfg |
|
114 | # generating all_tests.cfg |
|
91 | puts "generating testcase config file" |
|
115 | puts "generating testcase config file" |
|
92 |
|
116 | ||
|
93 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read |
|
117 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read |
|
94 | all_test_cfg = ERB.new(template) |
|
118 | all_test_cfg = ERB.new(template) |
|
95 |
|
119 | ||
|
96 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
120 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
97 | cfg_file.puts all_test_cfg.result |
|
121 | cfg_file.puts all_test_cfg.result |
|
98 | cfg_file.close |
|
122 | cfg_file.close |
|
99 |
|
123 | ||
|
100 |
|
124 | ||
|
101 | # copy check script |
|
125 | # copy check script |
|
102 | if res = /^wrapper:(.*)$/.match(check_script) |
|
126 | if res = /^wrapper:(.*)$/.match(check_script) |
|
103 | # wrapper script |
|
127 | # wrapper script |
|
104 | check_script_fname = res[1] |
|
128 | check_script_fname = res[1] |
|
105 | script_name = File.basename(check_script_fname) |
|
129 | script_name = File.basename(check_script_fname) |
|
106 | check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read |
|
130 | check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read |
|
107 | check_wrapper = ERB.new(check_wrapper_template) |
|
131 | check_wrapper = ERB.new(check_wrapper_template) |
|
108 |
|
132 | ||
|
109 | check_file = File.open("#{problem}/script/check","w") |
|
133 | check_file = File.open("#{problem}/script/check","w") |
|
110 | check_file.puts check_wrapper.result |
|
134 | check_file.puts check_wrapper.result |
|
111 | check_file.close |
|
135 | check_file.close |
|
112 |
|
136 | ||
|
113 | File.chmod(0755,"#{problem}/script/check") |
|
137 | File.chmod(0755,"#{problem}/script/check") |
@@ -1,13 +1,20 | |||||
|
1 | problem do |
|
1 | problem do |
|
2 | num_tests <%= num_testcases %> |
|
2 | num_tests <%= num_testcases %> |
|
3 |
- full_score <%= num_test |
|
3 | + full_score <%= num_testruns*10 %> |
|
4 | time_limit_each <%= options[:time_limit] %> |
|
4 | time_limit_each <%= options[:time_limit] %> |
|
5 | mem_limit_each <%= options[:mem_limit] %> |
|
5 | mem_limit_each <%= options[:mem_limit] %> |
|
6 | score_each 10 |
|
6 | score_each 10 |
|
7 |
|
7 | ||
|
8 | - <% 1.upto(num_testcases) do |i| %> |
|
8 | + <% tr_num = 0 %> |
|
9 | - run <%= i %> do |
|
9 | + <% testrun_info.each do |testrun| %> |
|
10 | - tests <%= i %> |
|
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 | end |
|
18 | end |
|
12 | <% end %> |
|
19 | <% end %> |
|
13 | end |
|
20 | end |
You need to be logged in to leave comments.
Login now