diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-21 15:35:29 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-21 15:35:29 +0000 |
commit | bd288dcc8bd661b51856e95a9d649a1130580627 (patch) | |
tree | 784a027c1e25467e66113278df99ccb0faed11a5 /test | |
parent | 4f618f5a0089af89069d6c547f8e4c4dc0a85410 (diff) | |
download | ruby-bd288dcc8bd661b51856e95a9d649a1130580627.tar.gz |
bigdecimal: version 1.3.0
Import bigdecimal version 1.3.0. The full commit log is here:
https://github.com/ruby/bigdecimal/compare/v1.3.0.pre.2...v1.3.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57145 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 45a65d8164..80ffc3fedd 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -1082,10 +1082,48 @@ class TestBigDecimal < Test::Unit::TestCase assert_equal(BigDecimal('-7.1364'), BigDecimal('-7.1364499').round(4, half: :down)) end + def test_round_half_nil + x = BigDecimal.new("2.5") + + BigDecimal.save_rounding_mode do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_UP) + assert_equal(3, x.round(0, half: nil)) + end + + BigDecimal.save_rounding_mode do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_DOWN) + assert_equal(2, x.round(0, half: nil)) + end + + BigDecimal.save_rounding_mode do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_UP) + assert_equal(3, x.round(0, half: nil)) + end + + BigDecimal.save_rounding_mode do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_DOWN) + assert_equal(2, x.round(0, half: nil)) + end + + BigDecimal.save_rounding_mode do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_EVEN) + assert_equal(2, x.round(0, half: nil)) + end + + BigDecimal.save_rounding_mode do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_CEILING) + assert_equal(3, x.round(0, half: nil)) + end + + BigDecimal.save_rounding_mode do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_FLOOR) + assert_equal(2, x.round(0, half: nil)) + end + end + def test_round_half_invalid_option assert_raise_with_message(ArgumentError, "invalid rounding mode: invalid") { BigDecimal('12.5').round(half: :invalid) } assert_raise_with_message(ArgumentError, "invalid rounding mode: invalid") { BigDecimal('2.15').round(1, half: :invalid) } - assert_raise_with_message(ArgumentError, "invalid rounding mode: nil") { BigDecimal('12.5').round(half: nil) } end def test_truncate |