[前][次][番号順一覧][スレッド一覧]

ruby-changes:3928

From: ko1@a...
Date: Sat, 9 Feb 2008 21:22:03 +0900 (JST)
Subject: [ruby-changes:3928] mame - Ruby:r15418 (trunk): * test/ruby/test_math.rb: add tests for Math#gamma, Math#lgamma and

mame	2008-02-09 21:21:30 +0900 (Sat, 09 Feb 2008)

  New Revision: 15418

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_math.rb

  Log:
    * test/ruby/test_math.rb: add tests for Math#gamma, Math#lgamma and
      Math#cbrt, and use assert_in_delta instead of assert.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15418&r2=15417&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_math.rb?r1=15418&r2=15417&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15417)
+++ ChangeLog	(revision 15418)
@@ -1,3 +1,8 @@
+Sat Feb  9 21:20:28 2008  Yusuke Endoh  <mame@t...>
+
+	* 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@f...>
 
 	* math.c (math_cbrt): new method Math.cbrt.
@@ -69,7 +74,7 @@
 
 	* lib/rdoc/ri/driver.rb (read_yaml): remove SM* for compatibility.
 
-Fri Feb 08 00:07:24 2008  Yusuke Endoh  <mame@t...>
+Fri Feb  8 00:07:24 2008  Yusuke Endoh  <mame@t...>
 
 	* test/ruby/test_hash.rb: follow the change of Hash#flatten.
 
Index: test/ruby/test_math.rb
===================================================================
--- test/ruby/test_math.rb	(revision 15417)
+++ test/ruby/test_math.rb	(revision 15418)
@@ -2,7 +2,7 @@
 
 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 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]