Description:
make .float checker better
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r239:dbdeebc3336d - - 1 file changed: 9 inserted, 0 deleted

@@ -26,41 +26,50
26 26 output_file_content = output_file.read
27 27 answer_file_content = answer_file.read
28 28
29 29 report_correct = lambda {
30 30 result_file.write "Correct\n"
31 31 result_file.write problem.get_score(test_num)
32 32 result_file.write "\n"
33 33 result_file.close
34 34 exit(0)
35 35 }
36 36
37 37 report_wrong = lambda {
38 38 result_file.write "Incorrect\n"
39 39 result_file.write "0\n"
40 40 result_file.close
41 41 exit(0)
42 42 }
43 43
44 44 ##################
45 45 # Your code here #
46 46 ##################
47 47
48 48 ########### THIS IS FOR CHECKING FLOAT with EPSILON error ##########
49 49
50 +
51 + def is_float?(fl)
52 + !!Float(fl) rescue false
53 + end
54 +
50 55 EPSILON = 0.000001
51 56
52 57 out_items = output_file_content.split
53 58 ans_items = answer_file_content.split
54 59
55 60 if out_items.length != ans_items.length
56 61 report_wrong.call
57 62 else
58 63 out_items.length.times do |i|
64 + if is_float?(out_items[i]) && is_float?(ans_items[i])
59 65 out_value = out_items[i].to_f
60 66 ans_value = ans_items[i].to_f
61 67 if (out_value - ans_value).abs > EPSILON * [out_value.abs,ans_value.abs].max
62 68 report_wrong.call
63 69 end
70 + else
71 + report_wrong.call if out_items[i] != ans_items[i]
72 + end
64 73 end
65 74 report_correct.call
66 75 end
You need to be logged in to leave comments. Login now