[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / test / -ext- / test_random.rb
blobe5cebcc871a5e8ee0a3f88b2cd4541962f11c29d
1 require 'test/unit'
3 module TestRandomExt
4   def setup
5     super
6     assert_nothing_raised(LoadError) {require '-test-/random'}
7   end
9   class TestLoop < Test::Unit::TestCase
10     include TestRandomExt
12     def test_bytes
13       rnd = Bug::Random::Loop.new(1)
14       assert_equal("\1", rnd.bytes(1))
15     end
17     def test_rand
18       rnd = Bug::Random::Loop.new(1)
19       assert_equal(1, rnd.rand(10))
20     end
22     def test_real
23       assert_equal(0.25, Bug::Random::Loop.new(1<<14).rand)
24       assert_equal(0.50, Bug::Random::Loop.new(2<<14).rand)
25       assert_equal(0.75, Bug::Random::Loop.new(3<<14).rand)
26       assert_equal(1.00, Bug::Random::Loop.new(4<<14).rand)
27     end
28   end
30   class TestVersionZero < Test::Unit::TestCase
31     include TestRandomExt
33     def test_bad_version
34       assert_raise(TypeError) {Bug::Random::VersionZero.new}
35     end
36   end
38   class TestVersionMax < Test::Unit::TestCase
39     include TestRandomExt
41     def test_bad_version
42       assert_raise(TypeError) {Bug::Random::VersionMax.new}
43     end
44   end
45 end