diff options
Diffstat (limited to 'mrbgems/mruby-array-ext/test/array.rb')
| -rw-r--r-- | mrbgems/mruby-array-ext/test/array.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb index 879980c7e..bd7a2dc45 100644 --- a/mrbgems/mruby-array-ext/test/array.rb +++ b/mrbgems/mruby-array-ext/test/array.rb @@ -18,6 +18,14 @@ def assert_combination(exp, receiver, *args) assert_permutation_combination(exp, receiver, :combination, *args) end +def assert_repeated_permutation(exp, receiver, *args) + assert_permutation_combination(exp, receiver, :repeated_permutation, *args) +end + +def assert_repeated_combination(exp, receiver, *args) + assert_permutation_combination(exp, receiver, :repeated_combination, *args) +end + assert("Array#assoc") do s1 = [ "colors", "red", "blue", "green" ] s2 = [ "letters", "a", "b", "c" ] @@ -443,3 +451,51 @@ assert "Array#product" do assert_equal base, base.product([4, 5, 6], [7, 8, 9]) { |e| x << e } assert_equal expect, x end + +assert("Array#repeated_combination") do + a = [1, 2, 3] + assert_raise(ArgumentError) { a.repeated_combination } + #assert_kind_of(Enumerator, a.repeated_combination(1)) + assert_repeated_combination([[1],[2],[3]], a, 1) + assert_repeated_combination([[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]], a, 2) + assert_repeated_combination([[1,1,1],[1,1,2],[1,1,3],[1,2,2],[1,2,3],[1,3,3],[2,2,2], + [2,2,3],[2,3,3],[3,3,3]], a, 3) + assert_repeated_combination([[1,1,1,1],[1,1,1,2],[1,1,1,3],[1,1,2,2],[1,1,2,3],[1,1,3,3], + [1,2,2,2],[1,2,2,3],[1,2,3,3],[1,3,3,3],[2,2,2,2],[2,2,2,3], + [2,2,3,3],[2,3,3,3],[3,3,3,3]], a, 4) + assert_repeated_combination([[1,1,1,1,1],[1,1,1,1,2],[1,1,1,1,3],[1,1,1,2,2],[1,1,1,2,3], + [1,1,1,3,3],[1,1,2,2,2],[1,1,2,2,3],[1,1,2,3,3],[1,1,3,3,3], + [1,2,2,2,2],[1,2,2,2,3],[1,2,2,3,3],[1,2,3,3,3],[1,3,3,3,3], + [2,2,2,2,2],[2,2,2,2,3],[2,2,2,3,3],[2,2,3,3,3],[2,3,3,3,3], + [3,3,3,3,3]], a, 5) + assert_repeated_combination([[]], a, 0) + assert_repeated_combination([], a, -1) +end + +assert("Array#repeated_permutation") do + a = [1, 2, 3] + assert_raise(ArgumentError) { a.repeated_permutation } + #assert_kind_of(Enumerator, a.repeated_permutation(1)) + assert_repeated_permutation([[1],[2],[3]], a, 1) + assert_repeated_permutation([[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[3,2],[3,3]], a, 2) + assert_repeated_permutation([[1,1,1],[1,1,2],[1,1,3],[1,2,1],[1,2,2],[1,2,3],[1,3,1],[1,3,2],[1,3,3], + [2,1,1],[2,1,2],[2,1,3],[2,2,1],[2,2,2],[2,2,3],[2,3,1],[2,3,2],[2,3,3], + [3,1,1],[3,1,2],[3,1,3],[3,2,1],[3,2,2],[3,2,3],[3,3,1],[3,3,2],[3,3,3]], + a, 3) + assert_repeated_permutation([[1,1,1,1],[1,1,1,2],[1,1,1,3],[1,1,2,1],[1,1,2,2],[1,1,2,3], + [1,1,3,1],[1,1,3,2],[1,1,3,3],[1,2,1,1],[1,2,1,2],[1,2,1,3], + [1,2,2,1],[1,2,2,2],[1,2,2,3],[1,2,3,1],[1,2,3,2],[1,2,3,3], + [1,3,1,1],[1,3,1,2],[1,3,1,3],[1,3,2,1],[1,3,2,2],[1,3,2,3], + [1,3,3,1],[1,3,3,2],[1,3,3,3],[2,1,1,1],[2,1,1,2],[2,1,1,3], + [2,1,2,1],[2,1,2,2],[2,1,2,3],[2,1,3,1],[2,1,3,2],[2,1,3,3], + [2,2,1,1],[2,2,1,2],[2,2,1,3],[2,2,2,1],[2,2,2,2],[2,2,2,3], + [2,2,3,1],[2,2,3,2],[2,2,3,3],[2,3,1,1],[2,3,1,2],[2,3,1,3], + [2,3,2,1],[2,3,2,2],[2,3,2,3],[2,3,3,1],[2,3,3,2],[2,3,3,3], + [3,1,1,1],[3,1,1,2],[3,1,1,3],[3,1,2,1],[3,1,2,2],[3,1,2,3], + [3,1,3,1],[3,1,3,2],[3,1,3,3],[3,2,1,1],[3,2,1,2],[3,2,1,3], + [3,2,2,1],[3,2,2,2],[3,2,2,3],[3,2,3,1],[3,2,3,2],[3,2,3,3], + [3,3,1,1],[3,3,1,2],[3,3,1,3],[3,3,2,1],[3,3,2,2],[3,3,2,3], + [3,3,3,1],[3,3,3,2],[3,3,3,3]], a, 4) + assert_repeated_permutation([[]], a, 0) + assert_repeated_permutation([], a, -1) +end |
