summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-array-ext
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-08-31 13:03:30 +0900
committerKOBAYASHI Shuji <[email protected]>2019-09-01 09:28:11 +0900
commitfe6cf851bf1080d1892f777987d2e52962d5f678 (patch)
treedead1df7ea2d36860a59df80c067f18ba3426d6a /mrbgems/mruby-array-ext
parent55ef4e4bdda01153c93cca26313d0329f765b591 (diff)
downloadmruby-fe6cf851bf1080d1892f777987d2e52962d5f678.tar.gz
mruby-fe6cf851bf1080d1892f777987d2e52962d5f678.zip
`Array#permutation` with a negative argument should not yield
Before this patch: $ bin/mruby -e '[1].permutation(-1){|v| p v}' #=> [1] After this patch (same as Ruby): $ bin/mruby -e '[1].permutation(-1){|v| p v}' #=> no output
Diffstat (limited to 'mrbgems/mruby-array-ext')
-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