From 100931ac2cc3b5c4e0c4dec9d91061de9e09f3da Mon Sep 17 00:00:00 2001 From: mrkn Date: Tue, 31 May 2011 14:43:39 +0000 Subject: * ext/bigdecimal/bigdecimal.c (GetVpValueWithPrec): replace the algorithm for coercing from a Rational to stop requiring "bigecimal/util.rb". [ruby-core:34318] * ext/bigdecimal/bigdecimal.c (GetVpValue): refactoring. * ext/bigdecimal/bigdecimal.c (BigDecimal_new): support instantiation from a Rational. * test/bigdecimal/test_bigdecimal.rb (test_global_new_with_rationao): add a test for the above change. * test/bigdecimal/test_bigdecimal.rb (test_new_with_rationao): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/bigdecimal/test_bigdecimal.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/bigdecimal/test_bigdecimal.rb') diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index d50b0e41c3..dd75dbfd64 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -36,6 +36,12 @@ class TestBigDecimal < Test::Unit::TestCase assert_equal(BigDecimal((-2**100).to_s), BigDecimal(-2**100)) end + def test_global_new_with_rational + assert_equal(BigDecimal("0.333333333333333333333"), BigDecimal(1.quo(3), 21)) + assert_equal(BigDecimal("-0.333333333333333333333"), BigDecimal(-1.quo(3), 21)) + assert_raise(ArgumentError) { BigDecimal(1.quo(3)) } + end + def test_new assert_equal(1, BigDecimal.new("1")) assert_equal(1, BigDecimal.new("1", 1)) @@ -58,6 +64,12 @@ class TestBigDecimal < Test::Unit::TestCase assert_equal(BigDecimal((-2**100).to_s), BigDecimal.new(-2**100)) end + def test_new_with_rational + assert_equal(BigDecimal("0.333333333333333333333"), BigDecimal.new(1.quo(3), 21)) + assert_equal(BigDecimal("-0.333333333333333333333"), BigDecimal.new(-1.quo(3), 21)) + assert_raise(ArgumentError) { BigDecimal.new(1.quo(3)) } + end + def _test_mode(type) BigDecimal.mode(type, true) assert_raise(FloatDomainError) { yield } -- cgit v1.2.3