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
This commit is contained in:
nobu 2013-02-22 03:46:47 +00:00
parent e51a9b49f1
commit 3f2ce6373f
5 changed files with 31 additions and 0 deletions

View file

@ -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