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

ruby-changes:33644

From: hsbt <ko1@a...>
Date: Sat, 26 Apr 2014 11:53:59 +0900 (JST)
Subject: [ruby-changes:33644] hsbt:r45725 (trunk): * test/ruby/test_enum.rb (test_flat_map): Added test for flat_map.

hsbt	2014-04-26 11:53:54 +0900 (Sat, 26 Apr 2014)

  New Revision: 45725

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

  Log:
    * test/ruby/test_enum.rb (test_flat_map): Added test for flat_map.
      Contribute from @igaiga. [fix GH-598]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_enum.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45724)
+++ ChangeLog	(revision 45725)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 26 11:50:08 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
+
+	* 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@r...>
 
 	* compile.c (compile_array_): make copy a first hash not to modify
Index: test/ruby/test_enum.rb
===================================================================
--- test/ruby/test_enum.rb	(revision 45724)
+++ test/ruby/test_enum.rb	(revision 45725)
@@ -592,4 +592,26 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L592
     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

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

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