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

ruby-changes:2097

From: ko1@a...
Date: 1 Oct 2007 23:46:18 +0900
Subject: [ruby-changes:2097] matz - Ruby:r13588 (trunk): * array.c (rb_ary_combination): revisit #combination behavior.

matz	2007-10-01 23:46:07 +0900 (Mon, 01 Oct 2007)

  New Revision: 13588

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/test/ruby/test_array.rb

  Log:
    * array.c (rb_ary_combination): revisit #combination behavior.
      suggested by David Flanagan.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=13588&r2=13587
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13588&r2=13587
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_array.rb?r1=13588&r2=13587

Index: array.c
===================================================================
--- array.c	(revision 13587)
+++ array.c	(revision 13588)
@@ -3028,13 +3028,11 @@
     RETURN_ENUMERATOR(ary, 1, &num);
     n = NUM2LONG(num);
     len = RARRAY_LEN(ary);
-    if (n < 1 || len < n) {
+    if (len < n) {
 	/* yield nothing */
     }
-    else if (n == 0) {
-	for (i = 0; i < len; i++) {
-	    rb_yield(rb_ary_new2(0));
-	}
+    else if (n <= 0) {
+	rb_yield(rb_ary_new2(0));
     }
     else if (n == 1) {
 	for (i = 0; i < len; i++) {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13587)
+++ ChangeLog	(revision 13588)
@@ -1,3 +1,8 @@
+Mon Oct  1 23:44:23 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* array.c (rb_ary_combination): revisit #combination behavior.
+	  suggested by David Flanagan.
+
 Mon Oct  1 16:17:44 2007  Tanaka Akira  <akr@f...>
 
 	* bootstraptest/test_method.rb: use assert_normal_exit to test
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb	(revision 13587)
+++ test/ruby/test_array.rb	(revision 13588)
@@ -1178,7 +1178,7 @@
   end
 
 # def test_permutation
-#    assert_equal(@cls[], @cls[1,2,3].permutation(0).to_a)
+#    assert_equal(@cls[[]], @cls[1,2,3].permutation(0).to_a)
 #    assert_equal(@cls[[1],[2],[3]], @cls[1,2,3].permutation(1).to_a)
 #    assert_equal(@cls[[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]], @cls[1,2,3].permutation(2).to_a)
 #    assert_equal(@cls[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]], @cls[1,2,3].permutation(3).to_a)
@@ -1186,7 +1186,7 @@
 #  end
 
  def test_combination
-    assert_equal(@cls[], @cls[1,2,3,4].combination(0).to_a)
+    assert_equal(@cls[[]], @cls[1,2,3,4].combination(0).to_a)
     assert_equal(@cls[[1],[2],[3],[4]], @cls[1,2,3,4].combination(1).to_a)
     assert_equal(@cls[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], @cls[1,2,3,4].combination(2).to_a)
     assert_equal(@cls[[1,2,3],[1,2,4],[1,3,4],[2,3,4]], @cls[1,2,3,4].combination(3).to_a)

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

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