From e2b192f7d5b4f0e2133bb6cf03cfc609258826be Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA Date: Sun, 15 Dec 2019 14:47:36 +0900 Subject: rand(beginless_range) raise Errno::EDOM instead of TypeError same as `rand(endless_range)` Before: ``` $ ruby -e 'rand(..1)' Traceback (most recent call last): 2: from -e:1:in `
' 1: from -e:1:in `rand' -e:1:in `-': nil can't be coerced into Integer (TypeError) ``` After: ``` $ ruby -e 'rand(..1)' Traceback (most recent call last): 1: from -e:1:in `
' -e:1:in `rand': Numerical argument out of domain (Errno::EDOM) ``` --- test/ruby/test_rand.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'test/ruby') diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb index ab9a1837f6..939d17bdf7 100644 --- a/test/ruby/test_rand.rb +++ b/test/ruby/test_rand.rb @@ -400,6 +400,7 @@ END assert_raise(Errno::EDOM, Errno::ERANGE) { r.rand(1.0 / 0.0) } assert_raise(Errno::EDOM, Errno::ERANGE) { r.rand(0.0 / 0.0) } assert_raise(Errno::EDOM) {r.rand(1..)} + assert_raise(Errno::EDOM) {r.rand(..1)} r = Random.new(0) assert_in_delta(1.5488135039273248, r.rand(1.0...2.0), 0.0001, '[ruby-core:24655]') -- cgit v1.2.3