Skip to content

Commit

Permalink
Merge pull request #12 from JuliaMath/teh/ranges
Browse files Browse the repository at this point in the history
Support conversions from Ranges
  • Loading branch information
ararslan authored Mar 13, 2017
2 parents 9c79dfc + 3c4a92a commit e83b982
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
4 changes: 4 additions & 0 deletions src/IntervalSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function convert{I<:AbstractInterval}(::Type{I}, i::AbstractInterval)
T = eltype(I)
I(convert(T, i.left), convert(T, i.right))
end
function convert{I<:AbstractInterval}(::Type{I}, r::Range)
T = eltype(I)
I(convert(T, minimum(r)), convert(T, maximum(r)))
end

ordered{T}(a::T, b::T) = ifelse(a < b, (a, b), (b, a))
ordered(a, b) = ordered(promote(a, b)...)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using Base.Test
@test eltype(I) == Int
@test eltype(M) == Float64
@test convert(ClosedInterval{Float64}, I) === 0.0..3.0
@test convert(ClosedInterval{Float64}, 0:3) === 0.0..3.0
@test !(convert(ClosedInterval{Float64}, I) === 0..3)
@test ClosedInterval{Float64}(1,3) === 1.0..3.0
@test ClosedInterval(0.5..2.5) === 0.5..2.5
Expand Down Expand Up @@ -81,3 +82,5 @@ using Base.Test
@test width(ClosedInterval(4.0,8.0)) 4.0
end
end

nothing

0 comments on commit e83b982

Please sign in to comment.