summaryrefslogtreecommitdiff
path: root/test/ruby/test_array.rb
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-24 14:01:21 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-24 14:01:21 +0000
commitf7d4df50c004d775a296b8989bb3ac792db6e639 (patch)
tree6c56a13e9bc39a93d0b176732eba60062ac133c6 /test/ruby/test_array.rb
parent3093546f1fd0b30cfccc8e13803126775cd70734 (diff)
* 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
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r--test/ruby/test_array.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 1b917ca77a..cfb36045e3 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -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