diff options
Diffstat (limited to 'test/ruby/test_rand.rb')
| -rw-r--r-- | test/ruby/test_rand.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb index 13b7329269..f177664943 100644 --- a/test/ruby/test_rand.rb +++ b/test/ruby/test_rand.rb @@ -317,7 +317,7 @@ class TestRand < Test::Unit::TestCase assert_equal(r1, r2, bug5661) assert_fork_status(1, '[ruby-core:82100] [Bug #13753]') do - Random::DEFAULT.rand(4) + Random.rand(4) end rescue NotImplementedError end @@ -336,6 +336,14 @@ class TestRand < Test::Unit::TestCase } end + def test_seed_leading_zero_guard + guard = 1<<32 + range = 0...(1<<32) + all_assertions_foreach(nil, 0, 1, 2) do |i| + assert_not_equal(Random.new(i).rand(range), Random.new(i+guard).rand(range)) + end + end + def test_marshal bug3656 = '[ruby-core:31622]' assert_raise(TypeError, bug3656) { @@ -395,8 +403,8 @@ class TestRand < Test::Unit::TestCase assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin; verbose, $VERBOSE = $VERBOSE, nil - seed = Random::DEFAULT::seed - rand1 = Random::DEFAULT::rand + seed = Random.seed + rand1 = Random.rand $VERBOSE = verbose rand2 = Random.new(seed).rand assert_equal(rand1, rand2) @@ -426,4 +434,9 @@ class TestRand < Test::Unit::TestCase # probability of failure <= 1/256**8 assert_operator(size.fdiv(n), :>, 15) end + + def test_broken_marshal + assert_raise(ArgumentError) { Marshal.load("\x04\bU:\vRandom" + Marshal.dump([1,0,1])[2..]) } + assert_raise(ArgumentError) { Marshal.load("\x04\bU:\vRandom" + Marshal.dump([1,-1,1])[2..]) } + end end |
