mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
37e432b5bf
commit
2406557794
2 changed files with 27 additions and 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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue