summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-02 05:20:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-02 05:20:51 +0000
commite626e0bdec56d15e01450509828f587cc5fa4687 (patch)
tree69e41da5fe299d192654898b1b44b7e6e4535e2a /test/ruby
parent3fcfe38c1a6a674d1438e8a8396cbe2cede9d196 (diff)
* random.c (rand_int): prevent from GC.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_rand.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb
index 2f2e772..e20cf4e 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