-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Implement a cmp specialization for ranges
#60337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
7ee77b2
80dd45a
3b6d103
3f344d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2831,3 +2831,30 @@ end | |||||
| @test StepRange(r) == r | ||||||
| @test StepRange(r) isa StepRange{Date,Day} | ||||||
| end | ||||||
|
|
||||||
| const EXAMPLE_RANGES = AbstractRange[ | ||||||
| 1:10, | ||||||
| 1:5, | ||||||
| 1:0, | ||||||
| 1:1, | ||||||
| 3:2, | ||||||
| 3:0, | ||||||
| 10:-1:1, | ||||||
| 1:2:10, | ||||||
| 10:-2:1, | ||||||
| LinRange(1.0, 10.0, 10), | ||||||
| LinRange(10.0, 1.0, 10), | ||||||
| 1e10:1.99:(1e10 + 2), | ||||||
| 1e10:(1.99+eps()):(1e10 + 2), | ||||||
| StepRangeLen(1, 2, 5), | ||||||
| StepRangeLen(10, -2, 5), | ||||||
| UInt8(1):UInt8(10), | ||||||
| UInt8(10):-UInt8(1):UInt8(1), | ||||||
| 'a':'z', | ||||||
| ] | ||||||
|
|
||||||
| @testset "cmp(::AbstractRange, ::AbstractRange)" begin | ||||||
| for a in EXAMPLE_RANGES, b in EXAMPLE_RANGES | ||||||
| @test try cmp(a, b) catch e; e end == try cmp(collect(a), collect(b)) catch e; e end | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Isn't exception handling done by
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or is this to compare that the errors are the same..? If so, IMO that should be done in a test explicit for that case, rather than mixing it into the general one. Alternatively we don't check this at all, since just comparing the thrown object doesn't mean that it's the same error - the location it was thrown from can be different too. |
||||||
| end | ||||||
| end | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last(zip(r1, r2))is still the abstract iterator's O(n) isn't it? And if we're doing an O(n) thing, we might as well compare everything, no? The goal here should be to detect the "fast" outs that are definitively correct, falling back to O(n) iteration if we can't do that.The worst case is where
stepis identical, but, yeah, it's tricky to rely onstep(r). Perhaps this should just be done forOrdinalRanges.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last(::Zip)is actuallyO(1)in most cases but I agree it will be challenging for any generic implementation to work for all ranges