Commit 6626fbc5 authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Refine `assert_float`

Avoid arithmetic operations when `exp` and/or `act` are infinity or NaN.
parent 6da10f64
......@@ -149,11 +149,11 @@ end
# Fails unless +exp+ is equal to +act+ in terms of a Float
def assert_float(exp, act, msg = nil)
e, a = exp.to_f, act.to_f
if (e.infinite? || a.infinite?) && e != a ||
if e.finite? && a.finite? && (n = (e - a).abs) > Mrbtest::FLOAT_TOLERANCE
flunk(msg, " Expected |#{exp} - #{act}| (#{n}) to be <= #{Mrbtest::FLOAT_TOLERANCE}.")
elsif (e.infinite? || a.infinite?) && e != a ||
e.nan? && !a.nan? || !e.nan? && a.nan?
flunk(msg, " Expected #{act} to be #{exp}.")
elsif (n = (e - a).abs) > Mrbtest::FLOAT_TOLERANCE
flunk(msg, " Expected |#{exp} - #{act}| (#{n}) to be <= #{Mrbtest::FLOAT_TOLERANCE}.")
else
pass
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment