diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-08-28 08:52:14 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-08-28 08:52:14 +0000 |
commit | a2bf9203e8b74065eb1452dd13741b3de7305eaf (patch) | |
tree | 5752281613cd54bb02b0668359a9429adede5422 /test/bigdecimal | |
parent | b6595225c1a68f212eb2d11f35de7732b9114fd7 (diff) |
* ext/bigdecimal/bigdecimal.c (BigDecimal_save_exception_mode,
BigDecimal_save_rounding_mode, BigDecimal_save_limit): added.
* test/bigdecimal/test_bigdecimal.rb: added tests for the above
features.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/bigdecimal')
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 7411416043..02a067a810 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -77,6 +77,42 @@ class TestBigDecimal < Test::Unit::TestCase end end + def test_save_exception_mode + BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false) + mode = BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW) + BigDecimal.save_exception_mode do + BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, true) + end + assert_equal(mode, BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW)) + + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_FLOOR) + BigDecimal.save_exception_mode do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_EVEN) + end + assert_equal(BigDecimal::ROUND_HALF_EVEN, BigDecimal.mode(BigDecimal::ROUND_MODE)) + end + + def test_save_rounding_mode + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_FLOOR) + BigDecimal.save_rounding_mode do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_EVEN) + end + assert_equal(BigDecimal::ROUND_FLOOR, BigDecimal.mode(BigDecimal::ROUND_MODE)) + end + + def test_save_limit + begin + old = BigDecimal.limit + BigDecimal.limit(100) + BigDecimal.save_limit do + BigDecimal.limit(200) + end + assert_equal(100, BigDecimal.limit); + ensure + BigDecimal.limit(old) + end + end + def test_exception_nan _test_mode(BigDecimal::EXCEPTION_NaN) { BigDecimal.new("NaN") } end |