* array.c (rb_ary_sample): rename #choice to #sample. in

addition, sample takes optional argument, a la #first.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-08-11 10:00:47 +00:00
parent 130e720253
commit 9295fd4b59
3 changed files with 47 additions and 11 deletions

View file

@ -1518,9 +1518,13 @@ class TestArray < Test::Unit::TestCase
end
end
def test_choice
def test_sample
100.times do
assert([0, 1, 2].include?([2, 1, 0].choice))
assert([0, 1, 2].include?([2, 1, 0].sample))
samples = [2, 1, 0].sample(2)
samples.each{|sample|
assert([0, 1, 2].include?(sample))
}
end
end