aboutsummaryrefslogtreecommitdiffstats
path: root/test/bigdecimal
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-21 15:35:29 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-21 15:35:29 +0000
commitaf3b3f2ad52c581ce140ca464b2a6982734e9fc8 (patch)
tree784a027c1e25467e66113278df99ccb0faed11a5 /test/bigdecimal
parentd0f17b6cc6b9a7d3380b0c748acf65f7d913476c (diff)
downloadruby-af3b3f2ad52c581ce140ca464b2a6982734e9fc8.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/bigdecimal')
-rw-r--r--test/bigdecimal/test_bigdecimal.rb40
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