diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_array.rb | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 9ab3168d73..2e9c6fca57 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1177,14 +1177,6 @@ class TestArray < Test::Unit::TestCase assert_equal(@cls[1,2], @cls[1, 2] | @cls[1, 2]) end -# def test_permutation -# assert_equal(@cls[[]], @cls[1,2,3].permutation(0).to_a) -# assert_equal(@cls[[1],[2],[3]], @cls[1,2,3].permutation(1).to_a) -# assert_equal(@cls[[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]], @cls[1,2,3].permutation(2).to_a) -# assert_equal(@cls[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]], @cls[1,2,3].permutation(3).to_a) -# assert_equal(@cls[], @cls[1,2,3].permutation(4).to_a) -# end - def test_combination assert_equal(@cls[[]], @cls[1,2,3,4].combination(0).to_a) assert_equal(@cls[[1],[2],[3],[4]], @cls[1,2,3,4].combination(1).to_a) @@ -1199,4 +1191,20 @@ class TestArray < Test::Unit::TestCase @cls[1,2,3].product([4,5])) assert_equal(@cls[[1,1],[1,2],[2,1],[2,2]], @cls[1,2].product([1,2])) end + + def test_permutation + a = @cls[1,2,3] + assert_equal(@cls[[]], a.permutation(0).to_a) + assert_equal(@cls[[1],[2],[3]], a.permutation(1).to_a.sort) + assert_equal(@cls[[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]], + a.permutation(2).to_a.sort) + assert_equal(@cls[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]], + a.permutation(3).sort.to_a) + assert_equal(@cls[], a.permutation(4).to_a) + assert_equal(@cls[], a.permutation(-1).to_a) + assert_equal("abcde".each_char.to_a.permutation(5).sort, + "edcba".each_char.to_a.permutation(5).sort) + assert_equal(@cls[].permutation(0).to_a, @cls[[]]) + + end end |