summaryrefslogtreecommitdiff
path: root/test/test_mathn.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_mathn.rb')
-rw-r--r--test/test_mathn.rb50
1 files changed, 46 insertions, 4 deletions
diff --git a/test/test_mathn.rb b/test/test_mathn.rb
index aaf132ba88..2ea049502c 100644
--- a/test/test_mathn.rb
+++ b/test/test_mathn.rb
@@ -96,17 +96,17 @@ class TestMathn < Test::Unit::TestCase
def test_round
assert_separately(%w[-rmathn], <<-EOS, ignore_stderr: true)
assert_equal( 3, ( 13/5).round)
- assert_equal( 3, ( 5/2).round)
+ assert_equal( 2, ( 5/2).round)
assert_equal( 2, ( 12/5).round)
assert_equal(-2, (-12/5).round)
- assert_equal(-3, ( -5/2).round)
+ assert_equal(-2, ( -5/2).round)
assert_equal(-3, (-13/5).round)
assert_equal( 3, ( 13/5).round(0))
- assert_equal( 3, ( 5/2).round(0))
+ assert_equal( 2, ( 5/2).round(0))
assert_equal( 2, ( 12/5).round(0))
assert_equal(-2, (-12/5).round(0))
- assert_equal(-3, ( -5/2).round(0))
+ assert_equal(-2, ( -5/2).round(0))
assert_equal(-3, (-13/5).round(0))
assert_equal(( 13/5), ( 13/5).round(2))
@@ -115,6 +115,48 @@ class TestMathn < Test::Unit::TestCase
assert_equal((-12/5), (-12/5).round(2))
assert_equal(( -5/2), ( -5/2).round(2))
assert_equal((-13/5), (-13/5).round(2))
+
+ assert_equal( 3, ( 13/5).round(half: :even))
+ assert_equal( 2, ( 5/2).round(half: :even))
+ assert_equal( 2, ( 12/5).round(half: :even))
+ assert_equal(-2, (-12/5).round(half: :even))
+ assert_equal(-2, ( -5/2).round(half: :even))
+ assert_equal(-3, (-13/5).round(half: :even))
+
+ assert_equal( 3, ( 13/5).round(0, half: :even))
+ assert_equal( 2, ( 5/2).round(0, half: :even))
+ assert_equal( 2, ( 12/5).round(0, half: :even))
+ assert_equal(-2, (-12/5).round(0, half: :even))
+ assert_equal(-2, ( -5/2).round(0, half: :even))
+ assert_equal(-3, (-13/5).round(0, half: :even))
+
+ assert_equal(( 13/5), ( 13/5).round(2, half: :even))
+ assert_equal(( 5/2), ( 5/2).round(2, half: :even))
+ assert_equal(( 12/5), ( 12/5).round(2, half: :even))
+ assert_equal((-12/5), (-12/5).round(2, half: :even))
+ assert_equal(( -5/2), ( -5/2).round(2, half: :even))
+ assert_equal((-13/5), (-13/5).round(2, half: :even))
+
+ assert_equal( 3, ( 13/5).round(half: :up))
+ assert_equal( 3, ( 5/2).round(half: :up))
+ assert_equal( 2, ( 12/5).round(half: :up))
+ assert_equal(-2, (-12/5).round(half: :up))
+ assert_equal(-3, ( -5/2).round(half: :up))
+ assert_equal(-3, (-13/5).round(half: :up))
+
+ assert_equal( 3, ( 13/5).round(0, half: :up))
+ assert_equal( 3, ( 5/2).round(0, half: :up))
+ assert_equal( 2, ( 12/5).round(0, half: :up))
+ assert_equal(-2, (-12/5).round(0, half: :up))
+ assert_equal(-3, ( -5/2).round(0, half: :up))
+ assert_equal(-3, (-13/5).round(0, half: :up))
+
+ assert_equal(( 13/5), ( 13/5).round(2, half: :up))
+ assert_equal(( 5/2), ( 5/2).round(2, half: :up))
+ assert_equal(( 12/5), ( 12/5).round(2, half: :up))
+ assert_equal((-12/5), (-12/5).round(2, half: :up))
+ assert_equal(( -5/2), ( -5/2).round(2, half: :up))
+ assert_equal((-13/5), (-13/5).round(2, half: :up))
EOS
end
end