Method: MiniTest::Assertions#assert_in_delta
- Defined in:
- lib/minitest/unit.rb
permalink #assert_in_delta(exp, act, delta = 0.001, msg = nil) ⇒ Object
For comparing Floats. Fails unless exp
and act
are within delta
of each other.
assert_in_delta Math::PI, (22.0 / 7.0), 0.01
125 126 127 128 129 |
# File 'lib/minitest/unit.rb', line 125 def assert_in_delta exp, act, delta = 0.001, msg = nil n = (exp - act).abs msg = (msg) { "Expected #{exp} - #{act} (#{n}) to be < #{delta}" } assert delta >= n, msg end |