summaryrefslogtreecommitdiff
path: root/test/ruby/test_float.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_float.rb')
-rw-r--r--test/ruby/test_float.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb
index b31c0415f2..f2989e4f5b 100644
--- a/test/ruby/test_float.rb
+++ b/test/ruby/test_float.rb
@@ -659,6 +659,48 @@ class TestFloat < Test::Unit::TestCase
}
end
+ def test_round_half_even
+ assert_equal(12.0, 12.5.round(half: :even))
+ assert_equal(14.0, 13.5.round(half: :even))
+
+ assert_equal(2.2, 2.15.round(1, half: :even))
+ assert_equal(2.2, 2.25.round(1, half: :even))
+ assert_equal(2.4, 2.35.round(1, half: :even))
+
+ assert_equal(-2.2, -2.15.round(1, half: :even))
+ assert_equal(-2.2, -2.25.round(1, half: :even))
+ assert_equal(-2.4, -2.35.round(1, half: :even))
+
+ assert_equal(7.1364, 7.13645.round(4, half: :even))
+ assert_equal(7.1365, 7.1364501.round(4, half: :even))
+ assert_equal(7.1364, 7.1364499.round(4, half: :even))
+
+ assert_equal(-7.1364, -7.13645.round(4, half: :even))
+ assert_equal(-7.1365, -7.1364501.round(4, half: :even))
+ assert_equal(-7.1364, -7.1364499.round(4, half: :even))
+ end
+
+ def test_round_half_up
+ assert_equal(13.0, 12.5.round(half: :up))
+ assert_equal(14.0, 13.5.round(half: :up))
+
+ assert_equal(2.2, 2.15.round(1, half: :up))
+ assert_equal(2.3, 2.25.round(1, half: :up))
+ assert_equal(2.4, 2.35.round(1, half: :up))
+
+ assert_equal(-2.2, -2.15.round(1, half: :up))
+ assert_equal(-2.3, -2.25.round(1, half: :up))
+ assert_equal(-2.4, -2.35.round(1, half: :up))
+
+ assert_equal(7.1365, 7.13645.round(4, half: :up))
+ assert_equal(7.1365, 7.1364501.round(4, half: :up))
+ assert_equal(7.1364, 7.1364499.round(4, half: :up))
+
+ assert_equal(-7.1365, -7.13645.round(4, half: :up))
+ assert_equal(-7.1365, -7.1364501.round(4, half: :up))
+ assert_equal(-7.1364, -7.1364499.round(4, half: :up))
+ end
+
def test_Float
assert_in_delta(0.125, Float("0.1_2_5"), 0.00001)
assert_in_delta(0.125, "0.1_2_5__".to_f, 0.00001)