Unverified Commit e8de7c68 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4681 from shuujii/array-permutation-with-a-negative-argument-should-not-yield

`Array#permutation` with a negative argument should not yield
parents 1a4ea94b fe6cf851
...@@ -819,7 +819,7 @@ class Array ...@@ -819,7 +819,7 @@ class Array
size = self.size size = self.size
if n == 0 if n == 0
yield [] yield []
elsif n <= size elsif 0 < n && n <= size
i = 0 i = 0
while i<size while i<size
result = [self[i]] result = [self[i]]
......
...@@ -392,6 +392,7 @@ assert("Array#permutation") do ...@@ -392,6 +392,7 @@ assert("Array#permutation") do
assert_permutation([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]], a, 3) assert_permutation([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]], a, 3)
assert_permutation([[]], a, 0) assert_permutation([[]], a, 0)
assert_permutation([], a, 4) assert_permutation([], a, 4)
assert_permutation([], a, -1)
end end
assert("Array#combination") do assert("Array#combination") do
...@@ -402,6 +403,7 @@ assert("Array#combination") do ...@@ -402,6 +403,7 @@ assert("Array#combination") do
assert_combination([[1,2,3,4]], a, 4) assert_combination([[1,2,3,4]], a, 4)
assert_combination([[]], a, 0) assert_combination([[]], a, 0)
assert_combination([], a, 5) assert_combination([], a, 5)
assert_combination([], a, -1)
end end
assert('Array#transpose') do assert('Array#transpose') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment