mirror of
https://github.com/ruby/ruby.git
synced 2025-08-27 06:56:13 +02:00
* array.c (rb_ary_permutation): Support for Array#permutation.size
[Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
55fb13eff9
commit
1cb9f27c13
2 changed files with 37 additions and 1 deletions
|
@ -429,5 +429,18 @@ class TestEnumerator < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def check_consistency_for_combinatorics(method)
|
||||
[ [], [:a, :b, :c, :d, :e] ].product([-2, 0, 2, 5, 6]) do |array, arg|
|
||||
assert_equal array.send(method, arg).to_a.size, array.send(method, arg).size,
|
||||
"inconsistent size for #{array}.#{method}(#{arg})"
|
||||
end
|
||||
end
|
||||
|
||||
def test_size_for_array_combinatorics
|
||||
check_consistency_for_combinatorics(:permutation)
|
||||
assert_equal 24, [0, 1, 2, 4].permutation.size
|
||||
assert_equal 2933197128679486453788761052665610240000000,
|
||||
(1..42).to_a.permutation(30).size # 1.upto(42).inject(:*) / 1.upto(12).inject(:*)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue