summaryrefslogtreecommitdiff
path: root/test/ruby/test_rand.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_rand.rb')
-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 2f2e772c1b0..e20cf4e317b 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