1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/ruby/test_math.rb: add tests for Math#gamma, Math#lgamma and

Math#cbrt, and use assert_in_delta instead of assert.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2008-02-09 12:21:30 +00:00
parent 87ea50380d
commit 7ced5439b4
2 changed files with 68 additions and 2 deletions

View file

@ -1,3 +1,8 @@
Sat Feb 9 21:20:28 2008 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_math.rb: add tests for Math#gamma, Math#lgamma and
Math#cbrt, and use assert_in_delta instead of assert.
Sat Feb 9 18:34:45 2008 Tanaka Akira <akr@fsij.org>
* math.c (math_cbrt): new method Math.cbrt.
@ -69,7 +74,7 @@ Fri Feb 8 09:27:57 2008 NARUSE, Yui <naruse@ruby-lang.org>
* lib/rdoc/ri/driver.rb (read_yaml): remove SM* for compatibility.
Fri Feb 08 00:07:24 2008 Yusuke Endoh <mame@tsg.ne.jp>
Fri Feb 8 00:07:24 2008 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_hash.rb: follow the change of Hash#flatten.

View file

@ -2,7 +2,7 @@ require 'test/unit'
class TestMath < Test::Unit::TestCase
def check(a, b)
assert(a - b < Float::EPSILON * 3)
assert_in_delta(a, b, Float::EPSILON * 4)
end
def test_atan2
@ -170,4 +170,65 @@ class TestMath < Test::Unit::TestCase
check(1, Math.erfc(0))
check(0, Math.erfc(1.0 / 0.0))
end
def test_gamma
sqrt_pi = Math.sqrt(Math::PI)
check(4 * sqrt_pi / 3, Math.gamma(-1.5))
check(-2 * sqrt_pi, Math.gamma(-0.5))
check(sqrt_pi, Math.gamma(0.5))
check(1, Math.gamma(1))
check(sqrt_pi / 2, Math.gamma(1.5))
check(1, Math.gamma(2))
check(3 * sqrt_pi / 4, Math.gamma(2.5))
check(2, Math.gamma(3))
check(15 * sqrt_pi / 8, Math.gamma(3.5))
check(6, Math.gamma(4))
end
def test_lgamma
sqrt_pi = Math.sqrt(Math::PI)
g, s = Math.lgamma(-1.5)
check(Math.log(4 * sqrt_pi / 3), g)
assert_equal(s, 1)
g, s = Math.lgamma(-0.5)
check(Math.log(2 * sqrt_pi), g)
assert_equal(s, -1)
g, s = Math.lgamma(0.5)
check(Math.log(sqrt_pi), g)
assert_equal(s, 1)
assert_equal([0, 1], Math.lgamma(1))
g, s = Math.lgamma(1.5)
check(Math.log(sqrt_pi / 2), g)
assert_equal(s, 1)
assert_equal([0, 1], Math.lgamma(2))
g, s = Math.lgamma(2.5)
check(Math.log(3 * sqrt_pi / 4), g)
assert_equal(s, 1)
g, s = Math.lgamma(3)
check(Math.log(2), g)
assert_equal(s, 1)
g, s = Math.lgamma(3.5)
check(Math.log(15 * sqrt_pi / 8), g)
assert_equal(s, 1)
g, s = Math.lgamma(4)
check(Math.log(6), g)
assert_equal(s, 1)
end
def test_cbrt
check(1, Math.cbrt(1))
check(-2, Math.cbrt(-8))
check(3, Math.cbrt(27))
check(-0.1, Math.cbrt(-0.001))
end
end