From d9876a53b51d56257982821789e05a41d03f0bc5 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 2 Aug 2009 05:20:51 +0000 Subject: * random.c (rand_int): prevent from GC. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_rand.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'test/ruby') 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 -- cgit