Class: Keisanjaku::Judge
- Inherits:
-
Object
- Object
- Keisanjaku::Judge
- Defined in:
- lib/keisanjaku/drill.rb
Instance Method Summary collapse
- #correct?(answer, true_value) ⇒ Boolean
-
#initialize(tolerance_percent: 1.0) ⇒ Judge
constructor
A new instance of Judge.
- #relative_error_percent(answer, true_value) ⇒ Object
Constructor Details
#initialize(tolerance_percent: 1.0) ⇒ Judge
Returns a new instance of Judge.
66 67 68 |
# File 'lib/keisanjaku/drill.rb', line 66 def initialize(tolerance_percent: 1.0) @tolerance_percent = Float(tolerance_percent) end |
Instance Method Details
#correct?(answer, true_value) ⇒ Boolean
70 71 72 |
# File 'lib/keisanjaku/drill.rb', line 70 def correct?(answer, true_value) relative_error_percent(answer, true_value).abs <= @tolerance_percent + 1e-12 end |
#relative_error_percent(answer, true_value) ⇒ Object
74 75 76 |
# File 'lib/keisanjaku/drill.rb', line 74 def relative_error_percent(answer, true_value) ((Float(answer) - Float(true_value)) / Float(true_value)) * 100.0 end |