From 4db4faef0f96bfd3504f5eac454a0308c618ccd6 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 1 Sep 2020 09:19:03 -0700 Subject: Revert "Fix Range#{max,minmax} for range with integer beginning and non-integer end" This reverts commit 8900a25581822759daca528d46a75e0b743fc22e. --- range.c | 21 +++------------------ test/ruby/test_range.rb | 13 ++----------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/range.c b/range.c index 124d9faa51..5e1103ce57 100644 --- a/range.c +++ b/range.c @@ -1235,13 +1235,6 @@ range_max(int argc, VALUE *argv, VALUE range) if (c > 0) return Qnil; if (EXCL(range)) { - if (RB_INTEGER_TYPE_P(b) && !RB_INTEGER_TYPE_P(e)) { - VALUE end = e; - e = rb_funcall(e, rb_intern("floor"), 0); - if (!RTEST(rb_funcall(e, rb_intern("=="), 1, end))) { - return e; - } - } if (!RB_INTEGER_TYPE_P(e)) { rb_raise(rb_eTypeError, "cannot exclude non Integer end value"); } @@ -1254,9 +1247,6 @@ range_max(int argc, VALUE *argv, VALUE range) } return rb_funcall(e, '-', 1, INT2FIX(1)); } - if (RB_INTEGER_TYPE_P(b) && !RB_INTEGER_TYPE_P(e)) { - e = rb_funcall(e, rb_intern("floor"), 0); - } return e; } } @@ -1604,14 +1594,9 @@ r_cover_range_p(VALUE range, VALUE beg, VALUE end, VALUE val) else if (cmp_end >= 0) { return TRUE; } - if (RB_INTEGER_TYPE_P(val_beg) && RB_INTEGER_TYPE_P(beg) && - RB_INTEGER_TYPE_P(val_end) != RB_INTEGER_TYPE_P(end)) { - val_max = val_end; - } - else { - val_max = rb_rescue2(r_call_max, val, 0, Qnil, rb_eTypeError, (VALUE)0); - if (val_max == Qnil) return FALSE; - } + + val_max = rb_rescue2(r_call_max, val, 0, Qnil, rb_eTypeError, (VALUE)0); + if (val_max == Qnil) return FALSE; return r_less(end, val_max) >= 0; } diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index 0b3f6c68f6..07a092858e 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -107,13 +107,11 @@ class TestRange < Test::Unit::TestCase assert_equal(1, (1...2).max) assert_raise(RangeError) { (1..).max } assert_raise(RangeError) { (1...).max } - assert_equal(2, (1..2.1).max) - assert_equal(2, (1...2.1).max) assert_equal(2.0, (1.0..2.0).max) assert_equal(nil, (2.0..1.0).max) assert_raise(TypeError) { (1.0...2.0).max } - assert_equal(1, (1...1.5).max) + assert_raise(TypeError) { (1...1.5).max } assert_raise(TypeError) { (1.5...2).max } assert_equal(-0x80000002, ((-0x80000002)...(-0x80000001)).max) @@ -139,13 +137,11 @@ class TestRange < Test::Unit::TestCase assert_equal([1, 1], (1...2).minmax) assert_raise(RangeError) { (1..).minmax } assert_raise(RangeError) { (1...).minmax } - assert_equal([1, 2], (1..2.1).minmax) - assert_equal([1, 2], (1...2.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_equal([1, 1], (1..1.5).minmax) + assert_raise(TypeError) { (1...1.5).minmax } assert_raise(TypeError) { (1.5...2).minmax } assert_equal([-0x80000002, -0x80000002], ((-0x80000002)...(-0x80000001)).minmax) @@ -660,12 +656,7 @@ class TestRange < Test::Unit::TestCase assert_not_operator(1..10, :cover?, 3...2) assert_not_operator(1..10, :cover?, 3...3) assert_not_operator('aa'..'zz', :cover?, 'aa'...'zzz') - assert_not_operator(1..10, :cover?, 1...10.1) - assert_not_operator(1...10.1, :cover?, 1..10.1) - assert_operator(1..10.1, :cover?, 1...10.1) - assert_operator(1..10.1, :cover?, 1...10) - assert_operator(1..10.1, :cover?, 1..10) end def test_beg_len -- cgit v1.2.3