diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-10-20 10:29:39 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-10-20 10:38:58 +0900 |
| commit | 0c3ee0ba66e4e7e0be6d652236240d74304f5e54 (patch) | |
| tree | 72b7fe5310d85a63fecd9c359b97aeb8b8068531 /mrbgems/mruby-array-ext/test | |
| parent | f2394859e37a3db4ca4a44510a34436a7ade635a (diff) | |
| download | mruby-0c3ee0ba66e4e7e0be6d652236240d74304f5e54.tar.gz mruby-0c3ee0ba66e4e7e0be6d652236240d74304f5e54.zip | |
Add `Array#{permutation,combination}.
Diffstat (limited to 'mrbgems/mruby-array-ext/test')
| -rw-r--r-- | mrbgems/mruby-array-ext/test/array.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb index c0db1b1cc..bf96b885e 100644 --- a/mrbgems/mruby-array-ext/test/array.rb +++ b/mrbgems/mruby-array-ext/test/array.rb @@ -381,3 +381,31 @@ assert("Array#slice!") do assert_equal(i, [1, 2, 3]) assert_equal(j, nil) end + +assert("Array#permutation") do + a = [1, 2, 3] + assert_equal([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]], + a.permutation.to_a) + assert_equal([[1],[2],[3]], + a.permutation(1).to_a) + assert_equal([[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]], + a.permutation(2).to_a) + assert_equal([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]], + a.permutation(3).to_a) + assert_equal([[]], a.permutation(0).to_a) + assert_equal([], a.permutation(4).to_a) +end + +assert("Array#combination") do + a = [1, 2, 3, 4] + assert_equal([[1],[2],[3],[4]], + a.combination(1).to_a) + assert_equal([[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], + a.combination(2).to_a) + assert_equal([[1,2,3],[1,2,4],[1,3,4],[2,3,4]], + a.combination(3).to_a) + assert_equal([[1,2,3,4]], + a.combination(4).to_a) + assert_equal([[]], a.combination(0).to_a) + assert_equal([], a.combination(5).to_a) +end |
