okkez e$B$G$9!#e(B
e$B%P%0$+$I$&$+<+?.$,;}$F$J$$$N$G3NG’$5$;$F$/$@$5$$!#e(B
MiniTest::Assertions#assert_in_delta
e$B$N%3!<%I$O0J2<$N$h$&$K$J$C$F$$$^$9!#e(B
Ruby1.9.2
##
# 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
def assert_in_delta exp, act, delta = 0.001, msg = nil
n = (exp - act).abs
msg = message(msg) { "Expected #{exp} - #{act} (#{n}) to be <
#{delta}" }
assert delta >= n, msg
end
##
# For comparing Floats. Fails unless +exp+ and +act+ have a
relative
# error less than +epsilon+.
def assert_in_epsilon a, b, epsilon = 0.001, msg = nil
assert_in_delta a, b, [a, b].min * epsilon, msg
end
assert_in_epsilon e$B$Oe(B assert_in_delta
e$B$r8F$S=P$7$F$$$k$N$G$^$H$a$F?t<0$C$]$/e(B
e$B=q$-2<$9$H8!::$7$F$$$kFbMF$O0J2<$N$h$&$K$J$k$H;W$$$^$9!#e(B
epsilon > 0 e$B$H$9$k!#e(B
epsilon >= |a - b|/min(a, b) — (x)
(1) a > 0, b > 0, a > b
(x) e$B$N1&JU$O@5e(B
(2) a < 0, b < 0, a > b
(x) e$B$N1&JU$OIie(B -> e$B>o$K%F%9%H$K%Q%9$7$F$7$^$&!)e(B
(3) a > 0, b < 0
(x) e$B$N1&JU$OIie(B -> e$B>o$K%F%9%H$K%Q%9$7$F$7$^$&!)e(B
(4) a < 0, b > 0
(x) e$B$N1&JU$OIie(B -> e$B>o$K%F%9%H$K%Q%9$7$F$7$^$&!)e(B
e$B$3$N;M$D$N>l9g$,$"$k$H;W$&$N$G$9$,!"$3$l$O%P%0$G$7$g$&$+!)e(B
e$B$=$l$H$b!“AjBP8m:9$r7W;;$9$k>l9g$O!“4|BTCM!”<BB,CM$H$b$K@5$NCM$Ge(B
e$B$”$kI,MW$,$"$k$N$G$7$g$&$+!#e(B