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

ruby-changes:7349

From: knu <ko1@a...>
Date: Tue, 26 Aug 2008 19:31:55 +0900 (JST)
Subject: [ruby-changes:7349] Ruby:r18868 (trunk): * test/ruby/test_enum.rb (TestEnumerable#test_each_with_object):

knu	2008-08-26 19:28:57 +0900 (Tue, 26 Aug 2008)

  New Revision: 18868

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18868

  Log:
    * test/ruby/test_enum.rb (TestEnumerable#test_each_with_object):
      Add a test for Enumerable#each_with_object.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_enum.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18867)
+++ ChangeLog	(revision 18868)
@@ -1,7 +1,12 @@
+Tue Aug 26 19:27:54 2008  Akinori MUSHA  <knu@i...>
+
+	* test/ruby/test_enum.rb (TestEnumerable#test_each_with_object):
+	  Add a test for Enumerable#each_with_object.
+
 Tue Aug 26 19:25:44 2008  Akinori MUSHA  <knu@i...>
 
 	* test/ruby/test_enumerator.rb (TestEnumerator#test_with_object):
-	  Add (back) the test for Enumerable#with_object.
+	  Add (back) the test for Enumerator#with_object.
 
 Tue Aug 26 16:16:43 2008  NARUSE, Yui  <naruse@r...>
 
Index: test/ruby/test_enum.rb
===================================================================
--- test/ruby/test_enum.rb	(revision 18867)
+++ test/ruby/test_enum.rb	(revision 18868)
@@ -196,6 +196,16 @@
     assert_equal({"cat"=>0, "wombat"=>2, "dog"=>1}, hash)
   end
 
+  def test_each_with_object
+    obj = [0, 1]
+    ret = (1..10).each_with_object(obj) {|i, memo|
+      memo[0] += i
+      memo[1] *= i
+    }
+    assert_same(obj, ret)
+    assert_equal([55, 3628800], ret)
+  end
+
   def test_zip
     assert_equal([[1,1],[2,2],[3,3],[1,1],[2,2]], @obj.zip(@obj))
     a = []

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

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