Skip to content

Commit

Permalink
Merge pull request #13 from JuliaMath/teh/ranges2
Browse files Browse the repository at this point in the history
Support conversion of AbstractInterval{<:Integer} to AbstractUnitRange
  • Loading branch information
timholy authored Mar 21, 2017
2 parents e83b982 + dbc316c commit 29998c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/IntervalSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ function convert{I<:AbstractInterval}(::Type{I}, r::Range)
T = eltype(I)
I(convert(T, minimum(r)), convert(T, maximum(r)))
end
function convert{R<:AbstractUnitRange,I<:Integer}(::Type{R}, i::AbstractInterval{I})
R(minimum(i), maximum(i))
end

ordered{T}(a::T, b::T) = ifelse(a < b, (a, b), (b, a))
ordered(a, b) = ordered(promote(a, b)...)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ using Base.Test
@test_throws ArgumentError :a .. "b"
I = 0..3
@test string(I) == "0..3"
@test convert(UnitRange, I) === 0:3
@test convert(UnitRange{Int16}, I) === Int16(0):Int16(3)
J = 3..2
K = 5..4
L = 3 ± 2
Expand Down

0 comments on commit 29998c5

Please sign in to comment.