ruby-changes:8391
From: mame <ko1@a...>
Date: Fri, 24 Oct 2008 23:01:34 +0900 (JST)
Subject: [ruby-changes:8391] Ruby:r19922 (trunk): * test/ruby/test_array.rb (test_sample): add tests for size of
mame 2008-10-24 23:01:21 +0900 (Fri, 24 Oct 2008) New Revision: 19922 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19922 Log: * test/ruby/test_array.rb (test_sample): add tests for size of returned array and randomness. Modified files: trunk/ChangeLog trunk/test/ruby/test_array.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 19921) +++ ChangeLog (revision 19922) @@ -1,3 +1,8 @@ +Fri Oct 24 22:59:27 2008 Yusuke Endoh <mame@t...> + + * 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@r...> * id.h, template/id.h.tmpl (enum ruby_method_ids): reordered. Index: test/ruby/test_array.rb =================================================================== --- test/ruby/test_array.rb (revision 19921) +++ test/ruby/test_array.rb (revision 19922) @@ -1545,6 +1545,23 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/