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 |
@@ -6,6 +6,7 | |||||
|
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" |
@@ -15,9 +16,16 | |||||
|
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) |
@@ -43,7 +51,7 | |||||
|
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 |
@@ -66,11 +74,13 | |||||
|
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 | ||
@@ -81,11 +91,25 | |||||
|
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 | ||
|
87 | end |
|
111 | end |
|
88 | - |
|
112 | + end |
|
89 |
|
113 | ||
|
90 | # generating all_tests.cfg |
|
114 | # generating all_tests.cfg |
|
91 | puts "generating testcase config file" |
|
115 | puts "generating testcase config file" |
@@ -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