Description:
add float value checking template with epsilon
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r153:ce30b9a1bad9 - - 1 file changed: 66 inserted, 0 deleted
@@ -0,0 +1,66 | |||||
|
|
1 | + #!/usr/bin/env 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 FLOAT with EPSILON error ########## | ||
|
|
49 | + | ||
|
|
50 | + EPSILON = 0.000001 | ||
|
|
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 | + out_value = out_items[i].to_f | ||
|
|
60 | + ans_value = ans_items[i].to_f | ||
|
|
61 | + if (out_value - ans_value).abs > EPSILON * [out_value.abs,ans_value.abs].max | ||
|
|
62 | + report_wrong.call | ||
|
|
63 | + end | ||
|
|
64 | + end | ||
|
|
65 | + report_correct.call | ||
|
|
66 | + end |
You need to be logged in to leave comments.
Login now