aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-10-01 14:46:07 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-10-01 14:46:07 +0000
commit25ff7ef4c68ef7b6f53a8eb61ef4ec57142852b9 (patch)
tree26c2ecff4ed2b78fd5a63eac3ecc1d9a5a82c59b
parent5838fff3341e6b4ebca956a6a96659eb5afb9859 (diff)
downloadruby-25ff7ef4c68ef7b6f53a8eb61ef4ec57142852b9.tar.gz
* array.c (rb_ary_combination): revisit #combination behavior.
suggested by David Flanagan. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--array.c8
-rw-r--r--test/ruby/test_array.rb4
3 files changed, 10 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index a56d0ca613..c1e718a16c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Oct 1 23:44:23 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * array.c (rb_ary_combination): revisit #combination behavior.
+ suggested by David Flanagan.
+
Mon Oct 1 16:17:44 2007 Tanaka Akira <akr@fsij.org>
* bootstraptest/test_method.rb: use assert_normal_exit to test
diff --git a/array.c b/array.c
index 0c25de0705..4c75c6d70d 100644
--- a/array.c
+++ b/array.c
@@ -3028,13 +3028,11 @@ rb_ary_combination(VALUE ary, VALUE num)
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++) {
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 4d2b05304b..9ab3168d73 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1178,7 +1178,7 @@ class TestArray < Test::Unit::TestCase
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 @@ class TestArray < Test::Unit::TestCase
# 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)