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 |
@@ -38,14 +38,22 | |||||
|
38 | SCRIPT_DIR = File.dirname(__FILE__) |
|
38 | SCRIPT_DIR = File.dirname(__FILE__) |
|
39 |
|
39 | ||
|
40 | # print usage |
|
40 | # print usage |
|
41 |
- if ARGV.length < |
|
41 | + if ARGV.length < 4 |
|
42 | puts <<USAGE |
|
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 | * creates a directory for a problem in the current directory, |
|
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 | * creates a test_request template in the current directory + '/test_request' |
|
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 | USAGE |
|
57 | USAGE |
|
50 | exit(127) |
|
58 | exit(127) |
|
51 | end |
|
59 | end |
@@ -54,14 +62,13 | |||||
|
54 | problem = ARGV[0] |
|
62 | problem = ARGV[0] |
|
55 | testcase_dir = ARGV[1] |
|
63 | testcase_dir = ARGV[1] |
|
56 | num_testcases = ARGV[2].to_i |
|
64 | num_testcases = ARGV[2].to_i |
|
57 | - |
|
65 | + check_script = ARGV[3] |
|
58 | options = {:time_limit => 1, :mem_limit => 16} |
|
66 | options = {:time_limit => 1, :mem_limit => 16} |
|
59 | process_options(options) |
|
67 | process_options(options) |
|
60 |
|
68 | ||
|
61 | # start working |
|
69 | # start working |
|
62 | puts "creating directories" |
|
70 | puts "creating directories" |
|
63 |
|
71 | ||
|
64 | - |
|
||
|
65 | system("mkdir #{problem}") |
|
72 | system("mkdir #{problem}") |
|
66 | system("mkdir #{problem}/script") |
|
73 | system("mkdir #{problem}/script") |
|
67 | system("mkdir #{problem}/test_cases") |
|
74 | system("mkdir #{problem}/test_cases") |
@@ -85,6 +92,15 | |||||
|
85 | cfg_file.puts all_test_cfg.result |
|
92 | cfg_file.puts all_test_cfg.result |
|
86 | cfg_file.close |
|
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 | # generating test_request directory |
|
104 | # generating test_request directory |
|
89 | puts "generating test_request template" |
|
105 | puts "generating test_request template" |
|
90 | FileUtils.mkdir_p("test_request/#{problem}/script") |
|
106 | FileUtils.mkdir_p("test_request/#{problem}/script") |
You need to be logged in to leave comments.
Login now