summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-23 22:07:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-23 22:07:39 +0000
commit2f6c0e3be38b057239eb044426c152ac5633c88f (patch)
tree694c7ce5c54b257050d1417974c970ec6cfd7651 /test
parent89339af9c19c28eaa9e2814fb75aa09768971f0e (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')
-rw-r--r--test/ruby/test_array.rb17
-rw-r--r--test/ruby/test_rand.rb1
2 files changed, 17 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
diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb
index 40b291f959..c3282cf804 100644
--- a/test/ruby/test_rand.rb
+++ b/test/ruby/test_rand.rb
@@ -171,6 +171,7 @@ class TestRand < Test::Unit::TestCase
def test_shuffle
srand(0)
assert_equal([1,4,2,5,3], [1,2,3,4,5].shuffle)
+ assert_equal([1,4,2,5,3], [1,2,3,4,5].shuffle(random: Random.new(0)))
end
def test_big_seed