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

ruby-changes:31631

From: headius <ko1@a...>
Date: Tue, 19 Nov 2013 04:02:18 +0900 (JST)
Subject: [ruby-changes:31631] headius:r43710 (trunk): * test/bigdecimal/test_bigdecimal.rb: incorporate BigMath.log

headius	2013-11-19 04:02:11 +0900 (Tue, 19 Nov 2013)

  New Revision: 43710

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43710

  Log:
    * test/bigdecimal/test_bigdecimal.rb: incorporate BigMath.log
      tests from JRuby by Peter Vandenabeele.

  Modified files:
    trunk/test/bigdecimal/test_bigdecimal.rb
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 43709)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 43710)
@@ -1,5 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L1
 require_relative "testbase"
 require_relative "../ruby/envutil"
+require 'bigdecimal/math'
 
 require 'thread'
 
@@ -1321,12 +1322,24 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L1322
     EOS
   end
 
+  def test_BigMath_log_with_string
+    assert_raise(ArgumentError) do
+      BigMath.log("foo", 20)
+    end
+  end
+
   def test_BigMath_log_with_nil
     assert_raise(ArgumentError) do
       BigMath.log(nil, 20)
     end
   end
 
+  def test_BigMath_log_with_non_integer_precision
+    assert_raise(ArgumentError) do
+      BigMath.log(1, 0.5)
+    end
+  end
+
   def test_BigMath_log_with_nil_precision
     assert_raise(ArgumentError) do
       BigMath.log(1, nil)
@@ -1339,7 +1352,19 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L1352
     end
   end
 
-  def test_BigMath_log_with_zerp_precision
+  def test_BigMath_log_with_zero_arg
+    assert_raise(Math::DomainError) do
+      BigMath.log(0, 20)
+    end
+  end
+
+  def test_BigMath_log_with_negative_arg
+    assert_raise(Math::DomainError) do
+      BigMath.log(-1, 20)
+    end
+  end
+
+  def test_BigMath_log_with_zero_precision
     assert_raise(ArgumentError) do
       BigMath.log(1, 0)
     end
@@ -1375,6 +1400,13 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L1400
     end
   end
 
+  def test_BigMath_log_with_float_nan
+    BigDecimal.save_exception_mode do
+      BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
+      assert(BigMath.log(Float::NAN, 20).nan?)
+    end
+  end
+
   def test_BigMath_log_with_1
     assert_in_delta(0.0, BigMath.log(1, 20))
     assert_in_delta(0.0, BigMath.log(1.0, 20))
@@ -1382,7 +1414,7 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L1414
   end
 
   def test_BigMath_log_with_exp_1
-    assert_in_delta(1.0, BigMath.log(BigMath.exp(1, 20), 20))
+    assert_in_delta(1.0, BigMath.log(BigMath.E(10), 10))
   end
 
   def test_BigMath_log_with_2
@@ -1391,8 +1423,15 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L1423
     assert_in_delta(Math.log(2), BigMath.log(BigDecimal(2), 20))
   end
 
-  def test_BigMath_log_with_square_of_exp_2
-    assert_in_delta(2, BigMath.log(BigMath.exp(1, 20)**2, 20))
+  def test_BigMath_log_with_square_of_E
+    assert_in_delta(2, BigMath.log(BigMath.E(20)**2, 20))
+  end
+
+  def test_BigMath_log_with_high_precision_case
+    e   = BigDecimal('2.71828182845904523536028747135266249775724709369996')
+    e_3 = e.mult(e, 50).mult(e, 50)
+    log_3 = BigMath.log(e_3, 50)
+    assert_in_delta(3, log_3, 0.0000000000_0000000000_0000000000_0000000000_0000000001)
   end
 
   def test_BigMath_log_with_42
@@ -1401,6 +1440,11 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L1440
     assert_in_delta(Math.log(42), BigMath.log(BigDecimal(42), 20))
   end
 
+  def test_BigMath_log_with_101
+    # this is mainly a performance test (should be very fast, not the 0.3 s)
+    assert_in_delta(Math.log(101), BigMath.log(101, 20), 1E-20)
+  end
+
   def test_BigMath_log_with_reciprocal_of_42
     assert_in_delta(Math.log(1e-42), BigMath.log(1e-42, 20))
     assert_in_delta(Math.log(1e-42), BigMath.log(BigDecimal("1e-42"), 20))

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

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