[前][次][番号順一覧][スレッド一覧]

ruby-changes:42225

From: nobu <ko1@a...>
Date: Sat, 26 Mar 2016 11:03:53 +0900 (JST)
Subject: [ruby-changes:42225] nobu:r54299 (trunk): test_integer.rb: refine test_round

nobu	2016-03-26 11:03:49 +0900 (Sat, 26 Mar 2016)

  New Revision: 54299

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54299

  Log:
    test_integer.rb: refine test_round
    
    * test/ruby/test_integer.rb (test_round): refine assertions and
      borrow from rubyspec.

  Modified files:
    trunk/test/ruby/test_integer.rb
Index: test/ruby/test_integer.rb
===================================================================
--- test/ruby/test_integer.rb	(revision 54298)
+++ test/ruby/test_integer.rb	(revision 54299)
@@ -165,26 +165,36 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_integer.rb#L165
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]