test/test_round.rb in flt-1.5.0 vs test/test_round.rb in flt-1.5.1
- old
+ new
@@ -1,9 +1,9 @@
require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
-class TestRound < Test::Unit::TestCase
+class TestRound < Minitest::Test
def setup
initialize_context
end
@@ -46,9 +46,44 @@
assert_equal(10, DecNum('9.99999').round(:rounding=>:half_up))
assert_equal(1, DecNum('0.999999').round(:rounding=>:half_up))
assert_equal(0, DecNum('0.0999999').round(:rounding=>:half_up))
assert_equal(1, DecNum('0.0999999').round(:rounding=>:up))
+ end
+
+ def test_ruby_2_4_round
+ assert_equal 100, DecNum('100.5').round(:half => :even)
+ assert_equal 101, DecNum('100.5000001').round(:half => :even)
+ assert_equal 102, DecNum('101.5').round(:half => :even)
+ assert_equal 101, DecNum('101.4999999999').round(:half => :even)
+
+ assert_equal 100, DecNum('100.5').round(:half => :down)
+ assert_equal 101, DecNum('100.5000001').round(:half => :down)
+ assert_equal 101, DecNum('101.5').round(:half => :down)
+ assert_equal 101, DecNum('101.4999999999').round(:half => :down)
+
+ assert_equal 101, DecNum('100.5').round(:half => :up)
+ assert_equal 101, DecNum('100.5000001').round(:half => :up)
+ assert_equal 102, DecNum('101.5').round(:half => :up)
+ assert_equal 101, DecNum('101.4999999999').round(:half => :up)
+
+ assert_equal 101, DecNum('100.5').round(0)
+ assert_equal DecNum('100.5'), DecNum('100.5').round(1)
+ assert_equal 100, DecNum('100.5').round(-1)
+ assert_equal DecNum('100.1235'), DecNum('100.1235'), DecNum('100.12345').round(4)
+
+ assert_equal 100, DecNum('100.5').round(0, :half => :even)
+ assert_equal 101, DecNum('100.5').round(0, :half => :up)
+ assert_equal 100, DecNum('100.5').round(0, :half => :down)
+ assert_equal DecNum('100.5'), DecNum('100.5').round(1, half: :even)
+ assert_equal DecNum('100.5'), DecNum('100.5').round(1, half: :up)
+ assert_equal DecNum('100.5'), DecNum('100.5').round(1, half: :down)
+ assert_equal 100, DecNum('100.5').round(-1, half: :even)
+ assert_equal 100, DecNum('100.5').round(-1, half: :down)
+ assert_equal 100, DecNum('100.5').round(-1, half: :up)
+ assert_equal DecNum('100.1234'), DecNum('100.12345').round(4, half: :even)
+ assert_equal DecNum('100.1235'), DecNum('100.12345').round(4, half: :up)
+ assert_equal DecNum('100.1234'), DecNum('100.12345').round(4, half: :down)
end
def detect_rounding(type)
x = type.new(1)*type.int_radix_power(type.context.precision+1)
y = x + type.int_radix_power(2)