From bb6384761e6c32acd169faa337d77d7e8d1efe5e Mon Sep 17 00:00:00 2001 From: mrkn Date: Mon, 27 Jun 2011 16:26:09 +0000 Subject: * ext/bigdecimal/bigdecimal.c (BigMath_s_log): move BigMath.log from bigdecimal/math.rb. * ext/bigdecimal/lib/bigdecimal/math.rb: ditto. * test/bigdecimal/test_bigdecimal.rb: move test for BigMath.log from test/bigdecimal/test_bigmath.rb. * test/bigdecimal/test_bigmath.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/bigdecimal/test_bigdecimal.rb | 85 ++++++++++++++++++++++++++++++++++++++ test/bigdecimal/test_bigmath.rb | 9 ---- 2 files changed, 85 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index b6ced686b6..7255179c6e 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -948,4 +948,89 @@ class TestBigDecimal < Test::Unit::TestCase assert_in_epsilon(Math.exp(-n), BigMath.exp(BigDecimal("-20"), n)) assert_in_epsilon(Math.exp(-40), BigMath.exp(BigDecimal("-40"), n)) end + + def test_BigMath_log_with_nil + assert_raise(ArgumentError) do + BigMath.log(nil, 20) + end + end + + def test_BigMath_log_with_nil_precision + assert_raise(ArgumentError) do + BigMath.log(1, nil) + end + end + + def test_BigMath_log_with_complex + assert_raise(Math::DomainError) do + BigMath.log(Complex(1, 2), 20) + end + end + + def test_BigMath_log_with_zerp_precision + assert_raise(ArgumentError) do + BigMath.log(1, 0) + end + end + + def test_BigMath_log_with_negative_precision + assert_raise(ArgumentError) do + BigMath.log(1, -42) + end + end + + def test_BigMath_log_with_negative_infinite + BigDecimal.save_exception_mode do + BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false) + assert_raise(Math::DomainError) do + BigMath.log(-BigDecimal::INFINITY, 20) + end + end + end + + def test_BigMath_log_with_positive_infinite + BigDecimal.save_exception_mode do + BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false) + assert(BigMath.log(BigDecimal::INFINITY, 20) > 0) + assert(BigMath.log(BigDecimal::INFINITY, 20).infinite?) + end + end + + def test_BigMath_log_with_nan + BigDecimal.save_exception_mode do + BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false) + assert(BigMath.log(BigDecimal::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)) + assert_in_delta(0.0, BigMath.log(BigDecimal(1), 20)) + end + + def test_BigMath_log_with_exp_1 + assert_in_delta(1.0, BigMath.log(BigMath.exp(1, 20), 20)) + end + + def test_BigMath_log_with_2 + assert_in_delta(Math.log(2), BigMath.log(2, 20)) + assert_in_delta(Math.log(2), BigMath.log(2.0, 20)) + 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)) + end + + def test_BigMath_log_with_42 + assert_in_delta(Math.log(42), BigMath.log(42, 20)) + assert_in_delta(Math.log(42), BigMath.log(42.0, 20)) + assert_in_delta(Math.log(42), BigMath.log(BigDecimal(42), 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)) + end end diff --git a/test/bigdecimal/test_bigmath.rb b/test/bigdecimal/test_bigmath.rb index fab559a085..2ccdb510f9 100644 --- a/test/bigdecimal/test_bigmath.rb +++ b/test/bigdecimal/test_bigmath.rb @@ -60,13 +60,4 @@ class TestBigMath < Test::Unit::TestCase assert_equal(BigDecimal("0.823840753418636291769355073102514088959345624027952954058347023122539489"), atan(BigDecimal("1.08"), 72).round(72), '[ruby-dev:41257]') end - - def test_log - assert_in_delta(0.0, log(BigDecimal("1"), N)) - assert_in_delta(1.0, log(E(N), N)) - assert_in_delta(Math.log(2.0), log(BigDecimal("2"), N)) - assert_in_delta(2.0, log(E(N)*E(N), N)) - assert_in_delta(Math.log(42.0), log(BigDecimal("42"), N)) - assert_in_delta(Math.log(1e-42), log(BigDecimal("1e-42"), N)) - end end -- cgit v1.2.3