aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_rand.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-22 03:46:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-22 03:46:47 +0000
commit3f2ce6373f7902e02c559876fb7255b5e36aaa64 (patch)
tree685108cad30bda565d1bd67f803546686f077691 /test/ruby/test_rand.rb
parente51a9b49f1ded288ee00732f0d7d4af01764a793 (diff)
downloadruby-3f2ce6373f7902e02c559876fb7255b5e36aaa64.tar.gz
random.c: fix error message
* random.c (rb_random_ulong_limited): fix error message for negative value. [ruby-dev:47061] [Bug #7903] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_rand.rb')
-rw-r--r--test/ruby/test_rand.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb
index b482773c00..9fabfc607f 100644
--- a/test/ruby/test_rand.rb
+++ b/test/ruby/test_rand.rb
@@ -1,4 +1,5 @@
require 'test/unit'
+require_relative 'envutil'
class TestRand < Test::Unit::TestCase
def assert_random_int(ws, m, init = 0)
@@ -514,4 +515,18 @@ END
l.call
end
end
+
+ def test_random_ulong_limited
+ def (gen = Object.new).rand(*) 1 end
+ assert_equal([2], (1..100).map {[1,2,3].sample(random: gen)}.uniq)
+
+ def (gen = Object.new).rand(*) 100 end
+ e = assert_raise(RangeError) {[1,2,3].sample(random: gen)}
+ assert_match(/big 100\z/, e.message)
+
+ bug7903 = '[ruby-dev:47061] [Bug #7903]'
+ def (gen = Object.new).rand(*) -1 end
+ e = assert_raise(RangeError) {[1,2,3].sample(random: gen)}
+ assert_match(/small -1\z/, e.message, bug7903)
+ end
end