From d5c60214c45bafc1cf2a516f852394986f9c84bb Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 7 Jun 2019 22:03:02 -0700 Subject: 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] --- test/ruby/test_range.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/ruby/test_range.rb') 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 } } -- cgit v1.2.3