From 631dde2572eb78cbf09d73d23a43852ccb199bd1 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 25 Nov 2016 06:28:00 +0000 Subject: 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 --- test/ruby/test_float.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/ruby/test_float.rb') 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") -- cgit v1.2.3