summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-26 02:03:49 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-26 02:03:49 +0000
commit4859714932aa8e67551580559b45e5fa21818384 (patch)
tree3366b62feadbf455adfb5368deaf824eb04ca491 /test
parent23e5b482ca4905c72395efddaabc98c13ceef19d (diff)
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
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_integer.rb48
1 files 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