diff options
| author | Emiliano Lesende <[email protected]> | 2013-11-02 12:07:34 -0300 |
|---|---|---|
| committer | Emiliano Lesende <[email protected]> | 2013-11-02 12:07:34 -0300 |
| commit | 80d8b5e2e71094a73dbc4a392ab9121c8c2f86ca (patch) | |
| tree | 432d4918f80e14b13185a0196f84cccb3428c0ed /mrbgems/mruby-random/test/random.rb | |
| parent | d8cc37cdf95b72933ff3d8466b8ea3c4e3ff8010 (diff) | |
| download | mruby-80d8b5e2e71094a73dbc4a392ab9121c8c2f86ca.tar.gz mruby-80d8b5e2e71094a73dbc4a392ab9121c8c2f86ca.zip | |
Added support for Random as an argument to shuffle and shuffle!. Refactored random gem to use DATA instance type and hold mt_state inside the DATA_PTR instead of in an instance variable.
Diffstat (limited to 'mrbgems/mruby-random/test/random.rb')
| -rw-r--r-- | mrbgems/mruby-random/test/random.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/mrbgems/mruby-random/test/random.rb b/mrbgems/mruby-random/test/random.rb index b35acaafd..c4e4082ad 100644 --- a/mrbgems/mruby-random/test/random.rb +++ b/mrbgems/mruby-random/test/random.rb @@ -43,4 +43,34 @@ assert('Array#shuffle!') do ary.shuffle! ary != [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and 10.times { |x| ary.include? x } +end + +assert("Array#shuffle(random)") do + assert_raise(TypeError) do + # this will cause an exception due to the wrong argument + [1, 2].shuffle "Not a Random instance" + end + + # verify that the same seed causes the same results + ary1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + shuffle1 = ary1.shuffle Random.new 345 + ary2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + shuffle2 = ary2.shuffle Random.new 345 + + ary1 != shuffle1 and 10.times { |x| shuffle1.include? x } and shuffle1 == shuffle2 +end + +assert('Array#shuffle!(random)') do + assert_raise(TypeError) do + # this will cause an exception due to the wrong argument + [1, 2].shuffle! "Not a Random instance" + end + + # verify that the same seed causes the same results + ary1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ary1.shuffle! Random.new 345 + ary2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ary2.shuffle! Random.new 345 + + ary1 != [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and 10.times { |x| ary1.include? x } and ary1 == ary2 end
\ No newline at end of file |
