diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-08-23 22:07:39 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-08-23 22:07:39 +0000 |
commit | 2f6c0e3be38b057239eb044426c152ac5633c88f (patch) | |
tree | 694c7ce5c54b257050d1417974c970ec6cfd7651 /test/ruby/test_array.rb | |
parent | 89339af9c19c28eaa9e2814fb75aa09768971f0e (diff) |
* array.c (rb_ary_shuffle_bang, rb_ary_sample): add optional
argument random. [ruby-dev:41923] [EXPERIMENTAL]
* random.c (rb_random_{int32,real,bytes}): fallback to normal
method invocation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r-- | test/ruby/test_array.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 3e32175012..f95d8870a1 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1891,6 +1891,12 @@ class TestArray < Test::Unit::TestCase 100.times do assert_equal([0, 1, 2], [2, 1, 0].shuffle.sort) end + + gen = Random.new(0) + srand(0) + 100.times do + assert_equal([0, 1, 2].shuffle, [0, 1, 2].shuffle(random: gen)) + end end def test_sample @@ -1907,7 +1913,7 @@ class TestArray < Test::Unit::TestCase (0..20).each do |n| 100.times do b = a.sample(n) - assert_equal([n, 18].min, b.uniq.size) + assert_equal([n, 18].min, b.size) assert_equal(a, (a | b).sort) assert_equal(b.sort, (a & b).sort) end @@ -1920,6 +1926,15 @@ class TestArray < Test::Unit::TestCase end assert_raise(ArgumentError, '[ruby-core:23374]') {[1, 2].sample(-1)} + + gen = Random.new(0) + srand(0) + a = (1..18).to_a + (0..20).each do |n| + 100.times do |i| + assert_equal(a.sample(n), a.sample(n, random: gen), "#{i}/#{n}") + end + end end def test_cycle |