diff options
author | Jeremy Evans <[email protected]> | 2019-06-07 22:03:02 -0700 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2019-08-14 11:22:07 -0700 |
commit | d5c60214c45bafc1cf2a516f852394986f9c84bb (patch) | |
tree | ce0ef54a02c893f3bae009cbd3477b082910f5c5 /test/ruby/test_range.rb | |
parent | 661927a4c55232bd070992d47670a7d411820111 (diff) |
Implement Range#minmax
Range#minmax was previous not implemented, so calling #minmax on
range was actually calling Enumerable#minmax. This is a simple
implementation of #minmax by just calling range_min and range_max.
Fixes [Bug #15867]
Fixes [Bug #15807]
Diffstat (limited to 'test/ruby/test_range.rb')
-rw-r--r-- | test/ruby/test_range.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index 14fd136aa6..699e4459be 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -121,6 +121,27 @@ class TestRange < Test::Unit::TestCase assert_raise(RangeError) { (1...).max(3) } end + def test_minmax + assert_equal([1, 2], (1..2).minmax) + assert_equal([nil, nil], (2..1).minmax) + assert_equal([1, 1], (1...2).minmax) + assert_raise(RangeError) { (1..).minmax } + assert_raise(RangeError) { (1...).minmax } + + assert_equal([1.0, 2.0], (1.0..2.0).minmax) + assert_equal([nil, nil], (2.0..1.0).minmax) + assert_raise(TypeError) { (1.0...2.0).minmax } + assert_raise(TypeError) { (1...1.5).minmax } + assert_raise(TypeError) { (1.5...2).minmax } + + assert_equal([-0x80000002, -0x80000002], ((-0x80000002)...(-0x80000001)).minmax) + + assert_equal([0, 0], (0..0).minmax) + assert_equal([nil, nil], (0...0).minmax) + + assert_equal([2, 1], (1..2).minmax{|a, b| b <=> a}) + end + def test_initialize_twice r = eval("1..2") assert_raise(NameError) { r.instance_eval { initialize 3, 4 } } |