diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-03-25 15:56:36 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-03-25 15:56:36 +0000 |
commit | 7e6dd6142e30e09976307e2626fd1ae9a36ab83e (patch) | |
tree | 4b08305d883b02298c1e1e55338022a9a43b4762 /test/ruby/test_rand.rb | |
parent | 43a2aaea2f307ed50fa059affa797a01ba62320d (diff) | |
download | ruby-7e6dd6142e30e09976307e2626fd1ae9a36ab83e.tar.gz |
* test/ruby/test_rand.rb: add tests to achieve over 95% test coverage
of random.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_rand.rb')
-rw-r--r-- | test/ruby/test_rand.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb index e2fd127f9c..b7d841dbba 100644 --- a/test/ruby/test_rand.rb +++ b/test/ruby/test_rand.rb @@ -128,4 +128,40 @@ class TestRand < Test::Unit::TestCase ws.each {|w| assert_equal(w.to_i, rand(-0x10000)) } end + def test_types + srand(0) + assert_equal(44, rand(100.0)) + assert_equal(1245085576965981900420779258691, rand((2**100).to_f)) + assert_equal(914679880601515615685077935113, rand(-(2**100).to_f)) + + srand(0) + assert_equal(997707939797331598305742933184, rand(2**100)) + assert_in_delta(0.602763376071644, rand((2**100).coerce(0).first), + 0.000000000000001) + + srand(0) + assert_in_delta(0.548813503927325, rand(nil), + 0.000000000000001) + srand(0) + o = Object.new + def o.to_i; 100; end + assert_equal(44, rand(o)) + assert_equal(47, rand(o)) + assert_equal(64, rand(o)) + end + + def test_srand + srand + assert_kind_of(Integer, rand(2)) + + srand(2**100) + %w(3258412053).each {|w| + assert_equal(w.to_i, rand(0x100000000)) + } + end + + def test_shuffle + srand(0) + assert_equal([1,4,2,5,3], [1,2,3,4,5].shuffle) + end end |