4 assert("Random#srand") do
10 assert("Kernel::srand") do
18 assert("Random::srand") do
27 rand(3).class == Fixnum
34 assert("Array#shuffle") do
35 ary = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
36 shuffled = ary.shuffle
38 ary == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and shuffled != ary and 10.times { |x| ary.include? x }
41 assert('Array#shuffle!') do
42 ary = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
45 ary != [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and 10.times { |x| ary.include? x }
48 assert("Array#shuffle(random)") do
49 assert_raise(TypeError) do
50 # this will cause an exception due to the wrong argument
51 [1, 2].shuffle "Not a Random instance"
54 # verify that the same seed causes the same results
55 ary1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
56 shuffle1 = ary1.shuffle Random.new 345
57 ary2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
58 shuffle2 = ary2.shuffle Random.new 345
60 ary1 != shuffle1 and 10.times { |x| shuffle1.include? x } and shuffle1 == shuffle2
63 assert('Array#shuffle!(random)') do
64 assert_raise(TypeError) do
65 # this will cause an exception due to the wrong argument
66 [1, 2].shuffle! "Not a Random instance"
69 # verify that the same seed causes the same results
70 ary1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
71 ary1.shuffle! Random.new 345
72 ary2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
73 ary2.shuffle! Random.new 345
75 ary1 != [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and 10.times { |x| ary1.include? x } and ary1 == ary2