mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* random.c (rand_int): prevent from GC.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3fcfe38c1a
commit
e626e0bdec
3 changed files with 33 additions and 13 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue