diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-09 09:01:40 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-09 09:01:40 +0000 |
commit | e3efce6df1aa691e17c59f442b35b4fd129d3a13 (patch) | |
tree | e1c5aed7b54721ba5a8a114bec1af03870545203 /test | |
parent | 7f8e5584649b1bba6d30d78c661a1b1eca28340e (diff) | |
download | ruby-e3efce6df1aa691e17c59f442b35b4fd129d3a13.tar.gz |
array.c: use rb_random_ulong_limited
* array.c (rb_ary_sample): use rb_random_ulong_limited, since
precision of long may be larger than double.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_array.rb | 8 | ||||
-rw-r--r-- | test/ruby/test_rand.rb | 5 |
2 files changed, 7 insertions, 6 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 60b08cd1bc..b4115ac5dd 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -2019,15 +2019,15 @@ class TestArray < Test::Unit::TestCase def test_sample_random ary = (0...10000).to_a assert_raise(ArgumentError) {ary.sample(1, 2, random: nil)} - gen0 = proc do - 0.5 + gen0 = proc do |max| + (max+1)/2 end class << gen0 alias rand call end - gen1 = proc do + gen1 = proc do |max| ary.replace([]) - 0.5 + (max+1)/2 end class << gen1 alias rand call diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb index 0b601628f6..fe88305788 100644 --- a/test/ruby/test_rand.rb +++ b/test/ruby/test_rand.rb @@ -170,8 +170,9 @@ 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))) + result = [*1..5].shuffle + assert_equal([*1..5], result.sort) + assert_equal(result, [*1..5].shuffle(random: Random.new(0))) end def test_big_seed |