Description:
[grader] update import_problem script, so that it requires check script.
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@109 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
r26:21e459268672 - - 3 files changed: 149 inserted, 7 deleted
@@ -0,0 +1,62 | |||
|
1 | + #!/usr/bin/ruby | |
|
2 | + | |
|
3 | + problem_home = ENV['PROBLEM_HOME'] | |
|
4 | + require "#{problem_home}/script/test_dsl.rb" | |
|
5 | + | |
|
6 | + if ARGV.length < 2 | |
|
7 | + puts "Usage: check <language> <test-number> [<output-file>]" | |
|
8 | + exit(0) | |
|
9 | + end | |
|
10 | + | |
|
11 | + language = ARGV[0] | |
|
12 | + test_num = ARGV[1].to_i | |
|
13 | + if ARGV.length >= 3 | |
|
14 | + output_file_name = ARGV[2] | |
|
15 | + else | |
|
16 | + output_file_name = "output.txt" | |
|
17 | + end | |
|
18 | + | |
|
19 | + load "#{problem_home}/test_cases/all_tests.cfg" | |
|
20 | + problem = Problem.get_instance | |
|
21 | + | |
|
22 | + output_file = File.new(output_file_name, "r") | |
|
23 | + answer_file = File.new("#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt") | |
|
24 | + result_file = File.new("check_result", "w") | |
|
25 | + | |
|
26 | + output_file_content = output_file.read | |
|
27 | + answer_file_content = answer_file.read | |
|
28 | + | |
|
29 | + report_correct = lambda { | |
|
30 | + result_file.write "Correct\n" | |
|
31 | + result_file.write problem.get_score(test_num) | |
|
32 | + result_file.write "\n" | |
|
33 | + result_file.close | |
|
34 | + exit(0) | |
|
35 | + } | |
|
36 | + | |
|
37 | + report_wrong = lambda { | |
|
38 | + result_file.write "Incorrect\n" | |
|
39 | + result_file.write "0\n" | |
|
40 | + result_file.close | |
|
41 | + exit(0) | |
|
42 | + } | |
|
43 | + | |
|
44 | + ################## | |
|
45 | + # Your code here # | |
|
46 | + ################## | |
|
47 | + | |
|
48 | + ########### THIS IS FOR CHECKING INTEGER ########## | |
|
49 | + num_pattern = /^[0-9]*/ | |
|
50 | + if (output_file_content =~ num_pattern) == nil | |
|
51 | + report_wrong.call | |
|
52 | + end | |
|
53 | + | |
|
54 | + output_i = output_file_content.to_i | |
|
55 | + answer_i = answer_file_content.to_i | |
|
56 | + | |
|
57 | + if output_i == answer_i | |
|
58 | + report_correct.call | |
|
59 | + else | |
|
60 | + report_wrong.call | |
|
61 | + end | |
|
62 | + |
@@ -0,0 +1,64 | |||
|
1 | + #!/usr/bin/ruby | |
|
2 | + | |
|
3 | + problem_home = ENV['PROBLEM_HOME'] | |
|
4 | + require "#{problem_home}/script/test_dsl.rb" | |
|
5 | + | |
|
6 | + if ARGV.length < 2 | |
|
7 | + puts "Usage: check <language> <test-number> [<output-file>]" | |
|
8 | + exit(0) | |
|
9 | + end | |
|
10 | + | |
|
11 | + language = ARGV[0] | |
|
12 | + test_num = ARGV[1].to_i | |
|
13 | + if ARGV.length >= 3 | |
|
14 | + output_file_name = ARGV[2] | |
|
15 | + else | |
|
16 | + output_file_name = "output.txt" | |
|
17 | + end | |
|
18 | + | |
|
19 | + load "#{problem_home}/test_cases/all_tests.cfg" | |
|
20 | + problem = Problem.get_instance | |
|
21 | + | |
|
22 | + output_file = File.new(output_file_name, "r") | |
|
23 | + answer_file = File.new("#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt") | |
|
24 | + result_file = File.new("check_result", "w") | |
|
25 | + | |
|
26 | + output_file_content = output_file.read | |
|
27 | + answer_file_content = answer_file.read | |
|
28 | + | |
|
29 | + report_correct = lambda { | |
|
30 | + result_file.write "Correct\n" | |
|
31 | + result_file.write problem.get_score(test_num) | |
|
32 | + result_file.write "\n" | |
|
33 | + result_file.close | |
|
34 | + exit(0) | |
|
35 | + } | |
|
36 | + | |
|
37 | + report_wrong = lambda { | |
|
38 | + result_file.write "Incorrect\n" | |
|
39 | + result_file.write "0\n" | |
|
40 | + result_file.close | |
|
41 | + exit(0) | |
|
42 | + } | |
|
43 | + | |
|
44 | + ################## | |
|
45 | + # Your code here # | |
|
46 | + ################## | |
|
47 | + | |
|
48 | + ########### THIS IS FOR CHECKING TEXT ########## | |
|
49 | + | |
|
50 | + # check visible text | |
|
51 | + | |
|
52 | + out_items = output_file_content.split | |
|
53 | + ans_items = answer_file_content.split | |
|
54 | + | |
|
55 | + if out_items.length != ans_items.length | |
|
56 | + report_wrong.call | |
|
57 | + else | |
|
58 | + out_items.length.times do |i| | |
|
59 | + if out_items[i]!=ans_items[i] | |
|
60 | + report_wrong.call | |
|
61 | + end | |
|
62 | + end | |
|
63 | + report_correct.call | |
|
64 | + end |
@@ -29,71 +29,87 | |||
|
29 | 29 | end |
|
30 | 30 | if ARGV[i]=='-m' |
|
31 | 31 | options[:mem_limit] = ARGV[i+1].to_i if ARGV.length>i+1 |
|
32 | 32 | i += 1 |
|
33 | 33 | end |
|
34 | 34 | i += 1 |
|
35 | 35 | end |
|
36 | 36 | end |
|
37 | 37 | |
|
38 | 38 | SCRIPT_DIR = File.dirname(__FILE__) |
|
39 | 39 | |
|
40 | 40 | # print usage |
|
41 |
- if ARGV.length < |
|
|
41 | + if ARGV.length < 4 | |
|
42 | 42 | puts <<USAGE |
|
43 |
- using: import_problem |
|
|
43 | + using: import_problem name dir num check [options] | |
|
44 | + where: name = problem_name [ | |
|
45 | + dir = importing testcase directory | |
|
46 | + num = number of testcases | |
|
47 | + check = check script, which can be | |
|
48 | + integer, text (for standard script), | |
|
49 | + or a path to a file | |
|
50 | + options: -t time-limit (in seconds) | |
|
51 | + -m memory-limit (in megabytes) | |
|
52 | + What it does: | |
|
44 | 53 | * creates a directory for a problem in the current directory, |
|
45 |
- * cop |
|
|
54 | + * copies testdata in the old format and create standard testcase config file | |
|
55 | + * copies a check script for grading | |
|
46 | 56 | * creates a test_request template in the current directory + '/test_request' |
|
47 | - * options: -t time-limit (in seconds) | |
|
48 | - -m memory-limit (in megabytes) | |
|
49 | 57 | USAGE |
|
50 | 58 | exit(127) |
|
51 | 59 | end |
|
52 | 60 | |
|
53 | 61 | # processing arguments |
|
54 | 62 | problem = ARGV[0] |
|
55 | 63 | testcase_dir = ARGV[1] |
|
56 | 64 | num_testcases = ARGV[2].to_i |
|
57 | - | |
|
65 | + check_script = ARGV[3] | |
|
58 | 66 | options = {:time_limit => 1, :mem_limit => 16} |
|
59 | 67 | process_options(options) |
|
60 | 68 | |
|
61 | 69 | # start working |
|
62 | 70 | puts "creating directories" |
|
63 | 71 | |
|
64 | - | |
|
65 | 72 | system("mkdir #{problem}") |
|
66 | 73 | system("mkdir #{problem}/script") |
|
67 | 74 | system("mkdir #{problem}/test_cases") |
|
68 | 75 | #system("cp #{GRADER_DIR}/std-script/* #{problem}/script") |
|
69 | 76 | |
|
70 | 77 | puts "copying testcases" |
|
71 | 78 | |
|
72 | 79 | 1.upto(num_testcases) do |i| |
|
73 | 80 | system("mkdir #{problem}/test_cases/#{i}") |
|
74 | 81 | copy_testcase("#{testcase_dir}","#{problem}/test_cases/#{i}",i) |
|
75 | 82 | end |
|
76 | 83 | |
|
77 | 84 | |
|
78 | 85 | # generating all_tests.cfg |
|
79 | 86 | puts "generating testcase config file" |
|
80 | 87 | |
|
81 | 88 | template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read |
|
82 | 89 | all_test_cfg = ERB.new(template) |
|
83 | 90 | |
|
84 | 91 | cfg_file = File.open("#{problem}/test_cases/all_tests.cfg","w") |
|
85 | 92 | cfg_file.puts all_test_cfg.result |
|
86 | 93 | cfg_file.close |
|
87 | 94 | |
|
95 | + | |
|
96 | + # copy check script | |
|
97 | + if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") | |
|
98 | + check_script_fname = SCRIPT_DIR + "/templates/check.#{check_script}" | |
|
99 | + else | |
|
100 | + check_script_fname = check_script | |
|
101 | + end | |
|
102 | + system("cp #{check_script_fname} #{problem}/script/check") | |
|
103 | + | |
|
88 | 104 | # generating test_request directory |
|
89 | 105 | puts "generating test_request template" |
|
90 | 106 | FileUtils.mkdir_p("test_request/#{problem}/script") |
|
91 | 107 | FileUtils.mkdir_p("test_request/#{problem}/test_cases/1") |
|
92 | 108 | |
|
93 | 109 | template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read |
|
94 | 110 | test_request_all_test_cfg = ERB.new(template) |
|
95 | 111 | |
|
96 | 112 | cfg_file = File.open("test_request/#{problem}/test_cases/all_tests.cfg","w") |
|
97 | 113 | cfg_file.puts test_request_all_test_cfg.result |
|
98 | 114 | cfg_file.close |
|
99 | 115 |
You need to be logged in to leave comments.
Login now