Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,11 @@ function _findin(r::AbstractRange{<:Integer}, span::AbstractUnitRange{<:Integer}
r isa AbstractUnitRange ? (ifirst:ilast) : (ifirst:1:ilast)
end

issubset(r::OneTo, s::OneTo) = r.stop <= s.stop

issubset(r::AbstractUnitRange{<:Integer}, s::AbstractUnitRange{<:Integer}) =
first(r) >= first(s) && last(r) <= last(s)

## linear operations on ranges ##

-(r::OrdinalRange) = range(-first(r), step=-step(r), length=length(r))
Expand Down
14 changes: 14 additions & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,20 @@ end
@test intersect(1:3, 2) === intersect(2, 1:3) === 2:2
@test intersect(1.0:3.0, 2) == intersect(2, 1.0:3.0) == [2.0]
end
@testset "issubset" begin
@test issubset(1:3, 1:typemax(Int)) #32461
@test issubset(1:3, 1:3)
@test issubset(1:3, 1:4)
@test issubset(1:3, 0:3)
@test issubset(1:3, 0:4)
@test !issubset(1:5, 2:5)
@test !issubset(1:5, 1:4)
@test !issubset(1:5, 2:4)
@test issubset(Base.OneTo(5), Base.OneTo(10))
@test !issubset(Base.OneTo(10), Base.OneTo(5))
@test issubset(1:3:10, 1:10)
@test !issubset(1:10, 1:3:10)
end
@testset "sort/sort!/partialsort" begin
@test sort(UnitRange(1,2)) == UnitRange(1,2)
@test sort!(UnitRange(1,2)) == UnitRange(1,2)
Expand Down