diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-26 02:53:54 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-26 02:53:54 +0000 |
commit | 24065577943091e542a414d1841ffd1ef43b9add (patch) | |
tree | 99f2478edac785182ca54c4f707e9aa84d607b97 | |
parent | 37e432b5bf4d873a987738891d86f588e97a53a6 (diff) |
* test/ruby/test_enum.rb (test_flat_map): Added test for flat_map.
Contribute from @igaiga. [fix GH-598]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | test/ruby/test_enum.rb | 22 |
2 files changed, 27 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Sat Apr 26 11:50:08 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com> + + * test/ruby/test_enum.rb (test_flat_map): Added test for flat_map. + Contribute from @igaiga. [fix GH-598] + Sat Apr 26 10:55:33 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> * compile.c (compile_array_): make copy a first hash not to modify diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index 963cd94034..7c8f37c8ce 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -592,4 +592,26 @@ class TestEnumerable < Test::Unit::TestCase assert_equal([['A',0], ['B',1], ['C',2], ['D',3], ['E',4]], @obj.each_with_index.map(&lambda2)) end + + def test_flat_map + @obj = [[1,2], [3,4]] + assert_equal([2,4,6,8], @obj.flat_map {|i| i.map{|j| j*2} }) + + proc = Proc.new {|i| i.map{|j| j*2} } + assert_equal([2,4,6,8], @obj.flat_map(&proc)) + + lambda = ->(i) { i.map{|j| j*2} } + assert_equal([2,4,6,8], @obj.flat_map(&lambda)) + + assert_equal([[1,2],0,[3,4],1], + @obj.each_with_index.flat_map {|x, i| [x,i] }) + + proc2 = Proc.new {|x, i| [x,i] } + assert_equal([[1,2],0,[3,4],1], + @obj.each_with_index.flat_map(&proc2)) + + lambda2 = ->(x, i) { [x,i] } + assert_equal([[1,2],0,[3,4],1], + @obj.each_with_index.flat_map(&lambda2)) + end end |