From dbc316c13665d352f203001d94d320b5b8db8e60 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Wed, 15 Mar 2017 13:51:25 -0500 Subject: [PATCH] Support conversion of AbstractInterval{<:Integer} to AbstractUnitRange --- src/IntervalSets.jl | 3 +++ test/runtests.jl | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/IntervalSets.jl b/src/IntervalSets.jl index 551db96..ee7f202 100644 --- a/src/IntervalSets.jl +++ b/src/IntervalSets.jl @@ -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)...) diff --git a/test/runtests.jl b/test/runtests.jl index 49f6ef6..7a822fa 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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