summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-17 17:38:14 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-17 17:38:14 +0000
commitf107d1e7066fdfa6360bf4aa9986f519dcd3f175 (patch)
treefff0efb2089cbee7737ff7407b8e8baa5cc196bf /test
parenta489109884de316893e3e716130be3a48bb965f0 (diff)
* ext/bigdecimal/bigdecimal.c (BigMath_s_exp): move BigMath.exp from
bigdecimal/math.rb. * ext/bigdecimal/lib/bigdecimal/math.rb: ditto. * test/bigdecimal/test_bigdecimal.rb: move test for BigMath.exp from test/bigdecimal/test_bigmath.rb. * test/bigdecimal/test_bigmath.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/bigdecimal/test_bigdecimal.rb52
-rw-r--r--test/bigdecimal/test_bigmath.rb16
2 files changed, 52 insertions, 16 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index 30044f1b6c..b6ced686b6 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -896,4 +896,56 @@ class TestBigDecimal < Test::Unit::TestCase
def test_NAN
assert(BigDecimal::NAN.nan?, "BigDecimal::NAN is not NaN")
end
+
+ def test_exp_with_zerp_precision
+ assert_raise(ArgumentError) do
+ BigMath.exp(1, 0)
+ end
+ end
+
+ def test_exp_with_negative_precision
+ assert_raise(ArgumentError) do
+ BigMath.exp(1, -42)
+ end
+ end
+
+ def test_exp_with_complex
+ assert_raise(ArgumentError) do
+ BigMath.exp(Complex(1, 2), 20)
+ end
+ end
+
+ def test_exp_with_negative_infinite
+ BigDecimal.save_exception_mode do
+ BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false)
+ assert_equal(0, BigMath.exp(-BigDecimal::INFINITY, 20))
+ end
+ end
+
+ def test_exp_with_positive_infinite
+ BigDecimal.save_exception_mode do
+ BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false)
+ assert(BigMath.exp(BigDecimal::INFINITY, 20) > 0)
+ assert(BigMath.exp(BigDecimal::INFINITY, 20).infinite?)
+ end
+ end
+
+ def test_exp_with_nan
+ BigDecimal.save_exception_mode do
+ BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
+ assert(BigMath.exp(BigDecimal::NAN, 20).nan?)
+ end
+ end
+
+ def test_exp_with_1
+ assert_in_epsilon(Math::E, BigMath.exp(1, 20))
+ end
+
+ def test_BigMath_exp
+ n = 20
+ assert_in_epsilon(Math.exp(n), BigMath.exp(BigDecimal("20"), n))
+ assert_in_epsilon(Math.exp(40), BigMath.exp(BigDecimal("40"), n))
+ assert_in_epsilon(Math.exp(-n), BigMath.exp(BigDecimal("-20"), n))
+ assert_in_epsilon(Math.exp(-40), BigMath.exp(BigDecimal("-40"), n))
+ end
end
diff --git a/test/bigdecimal/test_bigmath.rb b/test/bigdecimal/test_bigmath.rb
index ae3cb9d5f9..fab559a085 100644
--- a/test/bigdecimal/test_bigmath.rb
+++ b/test/bigdecimal/test_bigmath.rb
@@ -61,22 +61,6 @@ class TestBigMath < Test::Unit::TestCase
atan(BigDecimal("1.08"), 72).round(72), '[ruby-dev:41257]')
end
- def test_exp
- assert_in_epsilon(Math::E, exp(BigDecimal("1"), N))
- assert_in_epsilon(Math.exp(N), exp(BigDecimal("20"), N))
- assert_in_epsilon(Math.exp(40), exp(BigDecimal("40"), N))
- assert_in_epsilon(Math.exp(-N), exp(BigDecimal("-20"), N))
- assert_in_epsilon(Math.exp(-40), exp(BigDecimal("-40"), N))
- begin
- old_mode = BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY)
- BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false)
- assert(exp(BigDecimal::INFINITY, N).infinite?, "exp(INFINITY) is not an infinity")
- ensure
- #BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, old_mode)
- end
- assert_equal(0.0, exp(-BigDecimal::INFINITY, N))
- end
-
def test_log
assert_in_delta(0.0, log(BigDecimal("1"), N))
assert_in_delta(1.0, log(E(N), N))