Description:
make .float checker better
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r239:dbdeebc3336d - - 1 file changed: 9 inserted, 0 deleted
@@ -47,6 +47,11 | |||||
|
47 |
|
47 | ||
|
48 | ########### THIS IS FOR CHECKING FLOAT with EPSILON error ########## |
|
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 | EPSILON = 0.000001 |
|
55 | EPSILON = 0.000001 |
|
51 |
|
56 | ||
|
52 | out_items = output_file_content.split |
|
57 | out_items = output_file_content.split |
@@ -56,11 +61,15 | |||||
|
56 | report_wrong.call |
|
61 | report_wrong.call |
|
57 | else |
|
62 | else |
|
58 | out_items.length.times do |i| |
|
63 | out_items.length.times do |i| |
|
|
64 | + if is_float?(out_items[i]) && is_float?(ans_items[i]) | ||
|
59 | out_value = out_items[i].to_f |
|
65 | out_value = out_items[i].to_f |
|
60 | ans_value = ans_items[i].to_f |
|
66 | ans_value = ans_items[i].to_f |
|
61 | if (out_value - ans_value).abs > EPSILON * [out_value.abs,ans_value.abs].max |
|
67 | if (out_value - ans_value).abs > EPSILON * [out_value.abs,ans_value.abs].max |
|
62 | report_wrong.call |
|
68 | report_wrong.call |
|
63 | end |
|
69 | end |
|
|
70 | + else | ||
|
|
71 | + report_wrong.call if out_items[i] != ans_items[i] | ||
|
|
72 | + end | ||
|
64 | end |
|
73 | end |
|
65 | report_correct.call |
|
74 | report_correct.call |
|
66 | end |
|
75 | end |
You need to be logged in to leave comments.
Login now