summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-random/test/random.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-11-02 16:32:45 -0700
committerYukihiro "Matz" Matsumoto <[email protected]>2013-11-02 16:32:45 -0700
commite1f4e891c17d4367f1147c80b819b65b7fd3cb54 (patch)
tree432d4918f80e14b13185a0196f84cccb3428c0ed /mrbgems/mruby-random/test/random.rb
parentd2451dfb1660c219e7ba7bc2ae4ee859040b8d84 (diff)
parent80d8b5e2e71094a73dbc4a392ab9121c8c2f86ca (diff)
downloadmruby-e1f4e891c17d4367f1147c80b819b65b7fd3cb54.tar.gz
mruby-e1f4e891c17d4367f1147c80b819b65b7fd3cb54.zip
Merge pull request #1560 from 3miliano/master
Added support for Random as an argument to shuffle and shuffle!
Diffstat (limited to 'mrbgems/mruby-random/test/random.rb')
-rw-r--r--mrbgems/mruby-random/test/random.rb30
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