Skip to content

Commit 08fc04a

Browse files
committed
Convert Ranges to Intervals
1 parent 9c79dfc commit 08fc04a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/IntervalSets.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function convert{I<:AbstractInterval}(::Type{I}, i::AbstractInterval)
2323
T = eltype(I)
2424
I(convert(T, i.left), convert(T, i.right))
2525
end
26+
function convert{I<:AbstractInterval}(::Type{I}, r::Range)
27+
T = eltype(I)
28+
I(convert(T, minimum(r)), convert(T, maximum(r)))
29+
end
2630

2731
ordered{T}(a::T, b::T) = ifelse(a < b, (a, b), (b, a))
2832
ordered(a, b) = ordered(promote(a, b)...)

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ using Base.Test
2222
@test eltype(I) == Int
2323
@test eltype(M) == Float64
2424
@test convert(ClosedInterval{Float64}, I) === 0.0..3.0
25+
@test convert(ClosedInterval{Float64}, 0:3) === 0.0..3.0
2526
@test !(convert(ClosedInterval{Float64}, I) === 0..3)
2627
@test ClosedInterval{Float64}(1,3) === 1.0..3.0
2728
@test ClosedInterval(0.5..2.5) === 0.5..2.5
@@ -81,3 +82,5 @@ using Base.Test
8182
@test width(ClosedInterval(4.0,8.0)) 4.0
8283
end
8384
end
85+
86+
nothing

0 commit comments

Comments
 (0)