diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-02 05:20:51 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-02 05:20:51 +0000 |
commit | d9876a53b51d56257982821789e05a41d03f0bc5 (patch) | |
tree | 69e41da5fe299d192654898b1b44b7e6e4535e2a /test | |
parent | 3d6a864d52c8d28827d036d5fe6dcacfb23f14c1 (diff) | |
download | ruby-d9876a53b51d56257982821789e05a41d03f0bc5.tar.gz ruby-d9876a53b51d56257982821789e05a41d03f0bc5.tar.xz ruby-d9876a53b51d56257982821789e05a41d03f0bc5.zip |
* random.c (rand_int): prevent from GC.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_rand.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb index 2f2e772c1..e20cf4e31 100644 --- a/test/ruby/test_rand.rb +++ b/test/ruby/test_rand.rb @@ -4,13 +4,24 @@ class TestRand < Test::Unit::TestCase def assert_random_int(ws, m, init = 0) srand(init) rnds = [Random.new(init)] - ws.each do |w| + rnds2 = [rnds[0].dup] + rnds3 = [rnds[0].dup] + ws.each_with_index do |w, i| w = w.to_i assert_equal(w, rand(m)) rnds.each do |rnd| assert_equal(w, rnd.int(m)) end + rnds2.each do |rnd| + r=rnd.int(i...(m+i)) + assert_equal(w+i, r) + end + rnds3.each do |rnd| + r=rnd.int(i..(m+i-1)) + assert_equal(w+i, r) + end rnds << Marshal.load(Marshal.dump(rnds[-1])) + rnds2 << Marshal.load(Marshal.dump(rnds2[-1])) end end |