summaryrefslogtreecommitdiff
path: root/test/ruby/test_range.rb
AgeCommit message (Collapse)Author
2024-04-10[Misc #18984] Raise TypeError from Range#size if the range is not iterableKouhei Yanagita
2024-03-04[Bug #20324] Uncomparable ranges are not overlappingNobuyoshi Nakada
2023-12-22[Bug #19977] Fix (nil..nil) === x not to raise TypeErrorKouhei Yanagita
2023-11-28Make Range#reverse_each raise TypeError if endlessKouhei Yanagita
2023-10-26Make beginless Range#size return nil if it ends with non-numericfn ⌃ ⌥
2023-10-14[Bug #19926] Fix Range#size for ranges with a Rational endpointKouhei Yanagita
2023-10-12Add Range#reverse_each implementation for performanceKouhei Yanagita
2023-10-05Optimize `Range#count` by using `range_size` if possibleKouhei Yanagita
2023-09-21Optimize Range#bsearch for beginless/endless ranges within FixnumKouhei Yanagita
2023-09-16Fix regression when testing inclusion in unbounded rangesJeremy Evans
Caused by 04a92a6764bf678919cf4b68a27496a39d6b886a. This treats unbounded ranges of arbitrary objects the same as how unbounded string ranges are treated: (..x) === y # (y <=> x) <= 0 (...x) === y # (y <=> x) < 0 (x..) === y # (x <=> y) <= 0 Fixes [Bug #19864]
2023-09-16[Feature #19839] Fix `Range#overlap?` for empty rangesNobuyoshi Nakada
Empty ranges do not overlap with any range. Regarding benchmarks, PR#8242 is significantly faster in some cases, but one of these two cases is a wrong result. | |ActiveSupport| PR#8242|built-ruby| |:--------------------------|------------:|-------:|---------:| |(2..3).overlap?(1..1) | 7.761M| 15.053M| 32.368M| | | -| 1.94x| 4.17x| |(2..3).overlap?(2..4) | 25.720M| 55.070M| 21.981M| | | 1.17x| 2.51x| -| |(2..3).overlap?(4..5) | 7.616M| 15.048M| 21.730M| | | -| 1.98x| 2.85x| |(2..3).overlap?(2..1) | 25.585M| 56.545M| 32.786M| | | -| 2.21x| 1.28x| |(2..3).overlap?(0..1) | 7.554M| 14.755M| 32.545M| | | -| 1.95x| 4.31x| |(2..3).overlap?(...1) | 6.681M| 5.843M| 32.255M| | | 1.14x| -| 5.52x| |(2...3).overlap?(..2) | 6.676M| 5.817M| 21.572M| | | 1.15x| -| 3.71x| |(2...3).overlap?(3...) | 7.392M| 14.755M| 31.805M| | | -| 2.00x| 4.30x| |(2..3).overlap?('a'..'d') | 3.675M| 3.482M| 17.009M| | | 1.06x| -| 4.89x|
2023-09-16[Feature #19839] Add Range#overlap?Shouichi Kamiya
Add a method that returns true if two range overlap, otherwise false. ``` (0..10).overlap?(5..15) #=> true (0..10).overlap?(20..30) #=> false ```
2023-07-13Move bsearch test with Bigdecimal under the test_bigdecimal.rbHiroshi SHIBATA
When we extract bigdecimal as bundled gems, this test will be failed with `make test-all`.
2023-04-14[Bug #19533] Fix infinite range inclusion with numeric valueNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7574
2023-02-09[Bug #19426] Fix endless `Range#step` with `#succ` methodNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7277
2022-11-24Raise TypeError for endless non-numeric range include?Jeremy Evans
Beginless ranges previously raised TypeError for this case, except for string ranges, which had unexpected behavior: ('a'..'z').include?('ww') # false (..'z').include?('ww') # previously true, now TypeError Use of include? with endless ranges could previously result in an infinite loop. This splits off a range_string_cover_internal function from range_include_internal. Fixes [Bug #18580] Notes: Merged: https://github.com/ruby/ruby/pull/6261
2022-10-21Range#size returns nil for (.."a") and (nil..)Yusuke Endoh
Fixes [Bug #18983] Notes: Merged: https://github.com/ruby/ruby/pull/6604
2022-06-06Fix Range#cover? returning true for beginless ranges of different typesJeremy Evans
Previously `(2..).cover?("2"..)` was false, but `(..2).cover?(.."2")` was true. This changes it so both are false, treating beginless ranges the same as endless ranges in regards to type checks. This also adds documentation to #cover? to describe behavior with beginless and endless ranges, testing each documentation example, which is how this bug was found. Fixes [Bug #18155] Notes: Merged: https://github.com/ruby/ruby/pull/5831
2022-02-09Fix Range#include? for beginless exclusive string rangesJeremy Evans
Previously, include? would return true for the end of the range, when it should return false because the range is exclusive. Research and Analysis by Victor Shepelev. Fixes [Bug #18577] Notes: Merged: https://github.com/ruby/ruby/pull/5541
2020-10-23numeric.c, range.c: prohibit zero stepKenta Murata
* numeric.c: prohibit zero step in Numeric#step * range.c: prohibit zero step in Range#step * Fix ruby-spec [Feature #15573] Notes: Merged: https://github.com/ruby/ruby/pull/3689 Merged-By: mrkn <mrkn@ruby-lang.org>
2020-09-25freeze all Range objects.v3_0_0_preview1Koichi Sasada
Matz want to try to freeze all Range objects. [Feature #15504] Notes: Merged: https://github.com/ruby/ruby/pull/3583
2020-09-01Reapply "Special case Range#max for integer beginning and Float::Infinity ↵Marc-Andre Lafortune
end" (tests) Reverted in e080a4cdee Notes: Merged: https://github.com/ruby/ruby/pull/3501
2020-09-01Revert "Fix Range#{max,minmax} for range with integer beginning and ↵Jeremy Evans
non-integer end" This reverts commit 8900a25581822759daca528d46a75e0b743fc22e. Notes: Merged: https://github.com/ruby/ruby/pull/3500
2020-09-01Revert "Special case Range#max for integer beginning and Float::Infinity end"Jeremy Evans
This reverts commit 05bf811c2839628aaef3d565daedb28be80d47ef. Notes: Merged: https://github.com/ruby/ruby/pull/3500
2020-07-19Special case Range#max for integer beginning and Float::Infinity endJeremy Evans
Popular Ruby libraries such as Rails and Rubocop relying on the previous behavior, even though it is technically a bug. The correct behavior is probably raising RangeError, since that is what an endless range raises. Related to [Bug #17017]
2020-07-19Fix Range#max for beginless Integer ranges [Bug #17034]Michael Kohl
* Fix Range#max for beginless Integer ranges * Update test/ruby/test_range.rb * Fix formatting https://github.com/ruby/ruby/pull/3328 Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Notes: Merged-By: nobu <nobu@ruby-lang.org>
2020-07-13Fix Range#{max,minmax} for range with integer beginning and non-integer endJeremy Evans
Previously, for inclusive ranges, the max would show up as the end of the range, even though the end was not an integer and would not be the maximum value. For exclusive ranges, max/minmax would previously raise a TypeError, even though it is possible to get the correct maximum. This change to max/minmax also uncovered a similar error in cover?, which calls max in certain cases, so adjust the code there so that cover? still works as expected. Fixes [Bug #17017] Notes: Merged: https://github.com/ruby/ruby/pull/3306 Merged-By: jeremyevans <code@jeremyevans.net>
2020-07-04Fix non-numeric exclusive Range#minmax bugSam Bostock
The implementation of Range#minmax added in d5c60214c45 causes the following incorrect behaviour: ('a'...'c').minmax => ["a", ["a", "b"]] instead of ('a'...'c').minmax => ["a", "b"] This is because the C implementation of Range#minmax (range_minmax) directly delegates to the C implementation of Range#min (range_min) and Range#max (range_max), without changing the execution context. Range#max's C implementation (range_max), when given a non-numeric exclusive range, delegates to super, which is meant to call Enumerable#max. However, because range_max is called directly by range_minmax, super calls Enumerable#minmax instead, causing the incorrect nesting. Perhaps it is possible to change the execution context in an optimized manner, but the simplest solution seems to be to just explicitly delegate from Range#minmax to Range#min and Range#max. Notes: Merged: https://github.com/ruby/ruby/pull/3285
2019-12-25range.c: Range#min with a beginless one now raise an explicit exceptionYusuke Endoh
[Bug #16450]
2019-12-04implement Range#count卜部昌平
As matz requested in [Bug #16366].
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-08-29Aseert exception at negative step for non-endless range tooNobuyoshi Nakada
2019-08-14Make Range#=== operate like cover? instead of include? for string rangesJeremy Evans
Previously, Range#=== treated string ranges that were not endless or beginless the same as include?, instead of the same as cover?. I think this was an oversight in 989e07c0f2fa664a54e52a475c2fcc145f06539d, as the commit message did not indicate this behavior was desired. This also makes some previously dead code no longer dead. Previously, the conditionals were doing this: if (RB_TYPE_P(beg, T_STRING) if (NIL_P(beg)) # can never be true This restructures it so at the NIL_P(beg) check, beg could possibly be nil (beginless ranges). Fixes [Bug #15449]
2019-08-14Implement Range#minmaxJeremy Evans
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]
2019-05-23range.c (inspect_range): omit beginless "nil"Yusuke Endoh
except the special case `(nil..nil)`. ``` (1..).inspect #=> "1.." (..5).inspect #=> "..5" (nil..nil).inspect #=> "nil..nil" ``` [Bug #15745]
2019-05-01Add exception support in `Range#first`.manga_osyo
Closes: https://github.com/ruby/ruby/pull/2163
2019-04-08range.c: force hash values fixablenobu
* range.c (range_hash): force hash values fixable on LLP64 environment. [ruby-core:92194] [Bug #15757] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-04range.c: support to make beginless arithmetic sequencesmrkn
* range.c (range_step): fix the guard condition so that a beginless range can be turned into a beginless arithmetic sequence. * test/ruby/test_range.rb (test_step): add assertions for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-03range.c (r_cover_range_p): support beginless rangemame
`(..2).cover?(..1)` should return true. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-03Introduce beginless range [Feature#14799]mame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-24numeric.c: Fix negative step with float componentsmrkn
* numeric.c (ruby_float_step): fix negative step with float components. * test/ruby/test_numeric.c (test_step_bug15537): add tests. * test/ruby/test_range.c (test_step_bug15537): add tests. [Bug #15537] [ruby-core:91101] From: shuujii (Shuji KOBAYASHI) <shuujii@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-08range.c (range_last): disable optimization when each is redefinedmrkn
Do not use the optimized version of Range#last when Range#each is redefined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66749 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05test/ruby/test_range.rb: add assertionsmrkn
Add assertions of Range#first and Range#last to examine the type conversion of the arguments and the negative value check. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-28range.c: Add Range#%mrkn
[Feature #14697] [ruby-core:86588] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-05range.c: Range#cover? accepts Range object. [Feature #14473]tarui
* range.c (range_cover): add code for range argument. If the argument is a Range, check it is or is not covered by the reciver. If it can be treated as a sequence, this method treats it that way. * test/ruby/test_range.rb (class TestRange): add tests for this feature. This patch is written by Owen Stephens. thank you! git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-06enumerator.c: Introduce Enumerator::ArithmeticSequencemrkn
This commit introduces new core class Enumerator::ArithmeticSequence. Enumerator::ArithmeticSequence is a subclass of Enumerator, and represents a number generator of an arithmetic sequence. After this commit, Numeric#step and Range#step without blocks returned an ArithmeticSequence object instead of an Enumerator. This class introduces the following incompatibilities: - You can create a zero-step ArithmeticSequence, and its size is not ArgumentError, but Infinity. - You can create a negative-step ArithmeticSequence from a range. [ruby-core:82816] [Feature #13904] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-25test_range.rb: add tests to improve coveragewatson1978
This patch will improve the result of line coverage from 91.3% to 95.0%. [Fix GH-1899] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-22test/ruby/test_range.rb: add a test for endless range's min with comparisonmame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-22range.c: Range#last and #max raises a RangeError if it is endlessmame
Also, Range#min raises an error if it is endless and a comparison method is specified. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-22range.c: Range#size now returns Float::INFINITY if it is endlessmame
Fixes [Bug #14699] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e