From 4859714932aa8e67551580559b45e5fa21818384 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 26 Mar 2016 02:03:49 +0000 Subject: test_integer.rb: refine test_round * test/ruby/test_integer.rb (test_round): refine assertions and borrow from rubyspec. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_integer.rb | 48 ++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index d75926f004..3f5fca75d7 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -165,26 +165,36 @@ class TestInteger < Test::Unit::TestCase end end + def assert_int_equal(expected, result, mesg = nil) + assert_kind_of(Integer, result, mesg) + assert_equal(expected, result, mesg) + end + + def assert_float_equal(expected, result, mesg = nil) + assert_kind_of(Float, result, mesg) + assert_equal(expected, result, mesg) + end + def test_round - assert_equal(11111, 11111.round) - assert_equal(Fixnum, 11111.round.class) - assert_equal(11111, 11111.round(0)) - assert_equal(Fixnum, 11111.round(0).class) - - assert_equal(11111.0, 11111.round(1)) - assert_equal(Float, 11111.round(1).class) - assert_equal(11111.0, 11111.round(2)) - assert_equal(Float, 11111.round(2).class) - - assert_equal(11110, 11111.round(-1)) - assert_equal(Fixnum, 11111.round(-1).class) - assert_equal(11100, 11111.round(-2)) - assert_equal(Fixnum, 11111.round(-2).class) - - assert_equal(1111_1111_1111_1111_1111_1111_1111_1110, 1111_1111_1111_1111_1111_1111_1111_1111.round(-1)) - assert_equal(Bignum, 1111_1111_1111_1111_1111_1111_1111_1111.round(-1).class) - assert_equal(-1111_1111_1111_1111_1111_1111_1111_1110, (-1111_1111_1111_1111_1111_1111_1111_1111).round(-1)) - assert_equal(Bignum, (-1111_1111_1111_1111_1111_1111_1111_1111).round(-1).class) + assert_int_equal(11111, 11111.round) + assert_int_equal(11111, 11111.round(0)) + + assert_float_equal(11111.0, 11111.round(1)) + assert_float_equal(11111.0, 11111.round(2)) + + assert_int_equal(11110, 11111.round(-1)) + assert_int_equal(11100, 11111.round(-2)) + assert_int_equal(+200, +249.round(-2)) + assert_int_equal(+300, +250.round(-2)) + assert_int_equal(-200, -249.round(-2)) + assert_int_equal(-300, -250.round(-2)) + assert_int_equal(+30 * 10**70, (+25 * 10**70).round(-71)) + assert_int_equal(-30 * 10**70, (-25 * 10**70).round(-71)) + assert_int_equal(+20 * 10**70, (+25 * 10**70 - 1).round(-71)) + assert_int_equal(-20 * 10**70, (-25 * 10**70 + 1).round(-71)) + + assert_int_equal(1111_1111_1111_1111_1111_1111_1111_1110, 1111_1111_1111_1111_1111_1111_1111_1111.round(-1)) + assert_int_equal(-1111_1111_1111_1111_1111_1111_1111_1110, (-1111_1111_1111_1111_1111_1111_1111_1111).round(-1)) end def test_bitwise_and_with_integer_mimic_object -- cgit v1.2.3