summaryrefslogtreecommitdiff
path: root/test/bigdecimal/test_bigdecimal_util.rb
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-26 15:49:47 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-26 15:49:47 +0000
commitdca0b4177706c2cd9cda0d38af1b82752982e158 (patch)
tree127949dd094e102c5fde0dd73066c2e397134f34 /test/bigdecimal/test_bigdecimal_util.rb
parent079fb8d4c369cfc7d450d6e4d02b112596dcb5ee (diff)
* ext/bigdecimal/lib/bigdecimal/util.rb (Rational#to_d):
zero or negative precision is error. fixes #5098. [ruby-dev:44210] * test/bigdecimal/test_bigdecimal_util.rb: add test for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/bigdecimal/test_bigdecimal_util.rb')
-rw-r--r--test/bigdecimal/test_bigdecimal_util.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal_util.rb b/test/bigdecimal/test_bigdecimal_util.rb
index 87b4f20e99..72342b922f 100644
--- a/test/bigdecimal/test_bigdecimal_util.rb
+++ b/test/bigdecimal/test_bigdecimal_util.rb
@@ -25,4 +25,19 @@ class TestBigDecimalUtil < Test::Unit::TestCase
assert_in_delta(BigDecimal(0.5, 5), 0.5.to_d(digits), delta)
assert_in_delta(BigDecimal(355.0/113.0, 5), (355.0/113.0).to_d(digits), delta)
end
+
+ def test_Rational_to_d
+ digits = 100
+ delta = 1.0/10**(digits)
+ assert_in_delta(BigDecimal(1.quo(2), digits), 1.quo(2).to_d(digits), delta)
+ assert_in_delta(BigDecimal(355.quo(113), digits), 355.quo(113).to_d(digits), delta)
+ end
+
+ def test_Rational_to_d_with_zero_precision
+ assert_raise(ArgumentError) { 355.quo(113).to_d(0) }
+ end
+
+ def test_Rational_to_d_with_negative_precision
+ assert_raise(ArgumentError) { 355.quo(113).to_d(-42) }
+ end
end