diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | test/ruby/test_enum.rb | 10 |
2 files changed, 16 insertions, 1 deletions
@@ -1,7 +1,12 @@ +Tue Aug 26 19:27:54 2008 Akinori MUSHA <knu@iDaemons.org> + + * 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@iDaemons.org> * 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@ruby-lang.org> diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index a739982963..ed82d7787f 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -196,6 +196,16 @@ class TestEnumerable < Test::Unit::TestCase 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 = [] |