diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-10-01 23:35:30 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-10-01 23:35:30 +0000 |
commit | 04bc87e582ec83f56f3375724ef7370e53a914cd (patch) | |
tree | 03957401a7aaa4c25b5727046fb686cdafb8c8ec /test/ruby/test_array.rb | |
parent | 88f570d9ae5984decc313f10b54d259ff54fa525 (diff) | |
download | ruby-04bc87e582ec83f56f3375724ef7370e53a914cd.tar.gz |
* array.c (rb_ary_permutation): implementation contributed from
David Flanagan. [ruby-core:12344]
* array.c (rb_ary_combination): RDoc update to clarify. a patch
from David Flanagan. [ruby-core:12344]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_array.rb')
-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 |