1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/ruby/test_array.rb (test_sample): add tests for size of

returned array and randomness.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2008-10-24 14:01:21 +00:00
parent 3093546f1f
commit f7d4df50c0
2 changed files with 22 additions and 0 deletions

View file

@ -1,3 +1,8 @@
Fri Oct 24 22:59:27 2008 Yusuke Endoh <mame@tsg.ne.jp>
* test/ruby/test_array.rb (test_sample): add tests for size of
returned array and randomness.
Fri Oct 24 21:50:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* id.h, template/id.h.tmpl (enum ruby_method_ids): reordered.

View file

@ -1545,6 +1545,23 @@ class TestArray < Test::Unit::TestCase
assert([0, 1, 2].include?(sample))
}
end
srand(0)
a = (1..18).to_a
(0..20).each do |n|
10000.times do
b = a.sample(n)
assert_equal([n, 18].min, b.uniq.size)
assert_equal(a, (a | b).sort)
assert_equal(b.sort, (a & b).sort)
end
h = Hash.new(0)
10000.times do
a.sample(n).each {|x| h[x] += 1 }
end
assert_operator(h.values.min * 2, :>=, h.values.max) if n != 0
end
end
def test_cycle