* 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:
marcandre 2012-11-06 17:11:06 +00:00
parent 55fb13eff9
commit 1cb9f27c13
2 changed files with 37 additions and 1 deletions

View file

@ -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