summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-09-01 13:01:59 +0900
committerGitHub <[email protected]>2019-09-01 13:01:59 +0900
commite8de7c6819e85ba8cdd7825728db4a8a05605be0 (patch)
tree2ee9bd46b58c4327c87038d0c5a2f6a6ed5031fa
parent1a4ea94bc75a989a9077d968a567e23f7e90fc78 (diff)
parentfe6cf851bf1080d1892f777987d2e52962d5f678 (diff)
downloadmruby-e8de7c6819e85ba8cdd7825728db4a8a05605be0.tar.gz
mruby-e8de7c6819e85ba8cdd7825728db4a8a05605be0.zip
Merge pull request #4681 from shuujii/array-permutation-with-a-negative-argument-should-not-yield
`Array#permutation` with a negative argument should not yield
-rw-r--r--mrbgems/mruby-array-ext/mrblib/array.rb2
-rw-r--r--mrbgems/mruby-array-ext/test/array.rb2
2 files changed, 3 insertions, 1 deletions
diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb
index fef78f83f..fc5d87f2c 100644
--- a/mrbgems/mruby-array-ext/mrblib/array.rb
+++ b/mrbgems/mruby-array-ext/mrblib/array.rb
@@ -819,7 +819,7 @@ class Array
size = self.size
if n == 0
yield []
- elsif n <= size
+ elsif 0 < n && n <= size
i = 0
while i<size
result = [self[i]]
diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb
index 27075747e..a4e328b71 100644
--- a/mrbgems/mruby-array-ext/test/array.rb
+++ b/mrbgems/mruby-array-ext/test/array.rb
@@ -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([[]], a, 0)
assert_permutation([], a, 4)
+ assert_permutation([], a, -1)
end
assert("Array#combination") do
@@ -402,6 +403,7 @@ assert("Array#combination") do
assert_combination([[1,2,3,4]], a, 4)
assert_combination([[]], a, 0)
assert_combination([], a, 5)
+ assert_combination([], a, -1)
end
assert('Array#transpose') do