Class: Keisanjaku::Judge

Inherits:
Object
  • Object
show all
Defined in:
lib/keisanjaku/drill.rb

Instance Method Summary collapse

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

Returns:

  • (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