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

ruby-changes:42517

From: mrkn <ko1@a...>
Date: Fri, 15 Apr 2016 13:19:27 +0900 (JST)
Subject: [ruby-changes:42517] mrkn:r54591 (trunk): * test/ruby/test_array.rb (test_sum): add assertions for Rational and

mrkn	2016-04-15 14:16:04 +0900 (Fri, 15 Apr 2016)

  New Revision: 54591

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

  Log:
    * test/ruby/test_array.rb (test_sum): add assertions for Rational and
      Complex numbers.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_array.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54590)
+++ ChangeLog	(revision 54591)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Apr 15 14:14:00 2016  Kenta Murata  <mrkn@m...>
+
+	* test/ruby/test_array.rb (test_sum): add assertions for Rational and
+	  Complex numbers.
+
 Fri Apr 15 10:07:11 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/io/console/console.c (console_key_pressed_p): raise the same
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb	(revision 54590)
+++ test/ruby/test_array.rb	(revision 54591)
@@ -2714,14 +2714,25 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L2714
   FIXNUM_MIN = -(1 << (8 * RbConfig::SIZEOF['long'] - 2))
   FIXNUM_MAX = (1 << (8 * RbConfig::SIZEOF['long'] - 2)) - 1
 
-  def assert_int_equal(e, v, msg=nil)
-    assert_kind_of(Integer, v, msg)
+  def assert_typed_equal(e, v, cls, msg=nil)
+    assert_kind_of(cls, v, msg)
     assert_equal(e, v, msg)
   end
 
+  def assert_int_equal(e, v, msg=nil)
+    assert_typed_equal(e, v, Integer, msg)
+  end
+
+  def assert_rational_equal(e, v, msg=nil)
+    assert_typed_equal(e, v, Rational, msg)
+  end
+
   def assert_float_equal(e, v, msg=nil)
-    assert_equal(Float, v.class, msg)
-    assert_equal(e, v, msg)
+    assert_typed_equal(e, v, Float, msg)
+  end
+
+  def assert_complex_equal(e, v, msg=nil)
+    assert_typed_equal(e, v, Complex, msg)
   end
 
   def test_sum
@@ -2729,7 +2740,12 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L2740
     assert_int_equal(3, [3].sum)
     assert_int_equal(8, [3, 5].sum)
     assert_int_equal(15, [3, 5, 7].sum)
+    assert_rational_equal(8r, [3, 5r].sum)
     assert_float_equal(15.0, [3, 5, 7.0].sum)
+    assert_float_equal(15.0, [3, 5r, 7.0].sum)
+    assert_complex_equal(8r + 1i, [3, 5r, 1i].sum)
+    assert_complex_equal(15.0 + 1i, [3, 5r, 7.0, 1i].sum)
+
     assert_int_equal(2*FIXNUM_MAX, Array.new(2, FIXNUM_MAX).sum)
     assert_int_equal(2*(FIXNUM_MAX+1), Array.new(2, FIXNUM_MAX+1).sum)
     assert_int_equal(10*FIXNUM_MAX, Array.new(10, FIXNUM_MAX).sum)

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

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