* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / test / -ext- / test_random.rb
blob838e5d2f14211e96e02d6b0f6a1dff87e648c4f0
1 require 'test/unit'
3 module TestRandomExt
4   class TestLoop < Test::Unit::TestCase
5     def setup
6       super
7       assert_nothing_raised(LoadError) {require '-test-/random'}
8     end
10     def test_bytes
11       rnd = Bug::Random::Loop.new(1)
12       assert_equal("\1", rnd.bytes(1))
13     end
15     def test_rand
16       rnd = Bug::Random::Loop.new(1)
17       assert_equal(1, rnd.rand(10))
18     end
20     def test_real
21       assert_equal(0.25, Bug::Random::Loop.new(1<<14).rand)
22       assert_equal(0.50, Bug::Random::Loop.new(2<<14).rand)
23       assert_equal(0.75, Bug::Random::Loop.new(3<<14).rand)
24       assert_equal(1.00, Bug::Random::Loop.new(4<<14).rand)
25     end
26   end
27 end