summaryrefslogtreecommitdiff
path: root/test/ruby/test_float.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-25 06:28:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-25 06:28:00 +0000
commit631dde2572eb78cbf09d73d23a43852ccb199bd1 (patch)
treed85aad8b66468b69730c9a85362879b56f5aa41a /test/ruby/test_float.rb
parentb6d10b6c378edcb88d3238b5c862e585ad9c8b33 (diff)
round-down
* numeric.c (round_half_down, int_round_half_down): support round-down mode. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_float.rb')
-rw-r--r--test/ruby/test_float.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb
index 74744bfaa2..aed387029e 100644
--- a/test/ruby/test_float.rb
+++ b/test/ruby/test_float.rb
@@ -701,6 +701,27 @@ class TestFloat < Test::Unit::TestCase
assert_equal(-7.1364, -7.1364499.round(4, half: :up))
end
+ def test_round_half_down
+ assert_equal(12.0, 12.5.round(half: :down))
+ assert_equal(13.0, 13.5.round(half: :down))
+
+ assert_equal(2.1, 2.15.round(1, half: :down))
+ assert_equal(2.2, 2.25.round(1, half: :down))
+ assert_equal(2.3, 2.35.round(1, half: :down))
+
+ assert_equal(-2.1, -2.15.round(1, half: :down))
+ assert_equal(-2.2, -2.25.round(1, half: :down))
+ assert_equal(-2.3, -2.35.round(1, half: :down))
+
+ assert_equal(7.1364, 7.13645.round(4, half: :down))
+ assert_equal(7.1365, 7.1364501.round(4, half: :down))
+ assert_equal(7.1364, 7.1364499.round(4, half: :down))
+
+ assert_equal(-7.1364, -7.13645.round(4, half: :down))
+ assert_equal(-7.1365, -7.1364501.round(4, half: :down))
+ assert_equal(-7.1364, -7.1364499.round(4, half: :down))
+ end
+
def test_round_half_invalid
assert_raise_with_message(ArgumentError, /xxx/) {
1.0.round(half: "\0xxx")