diff --git a/src/interval.jl b/src/interval.jl index 023e2da..1299b09 100644 --- a/src/interval.jl +++ b/src/interval.jl @@ -27,14 +27,7 @@ mathematical notation, the constructed range is `(left, right)`. const OpenInterval{T} = Interval{:open,:open,T} Interval{L,R,T}(i::AbstractInterval) where {L,R,T} = Interval{L,R,T}(endpoints(i)...) -function Interval{L,R}(left, right) where {L,R} - # TODO: Replace the retrun value with `Interval{L,R}(promote(left,right)...)`. (#93) - T = promote_type(typeof(left), typeof(right)) - if !isconcretetype(T) - Base.depwarn("`Promotion to a concrete type failed and will error in the next release; consider constructing this interval as `Interval{L,R,$(typejoin(typeof(left),typeof(right)))}(left, right)`.", :Interval) - end - Interval{L,R,T}(left,right) -end +Interval{L,R}(left, right) where {L,R} = Interval{L,R}(promote(left,right)...) Interval{L,R}(left::T, right::T) where {L,R,T} = Interval{L,R,T}(left, right) Interval(left, right) = ClosedInterval(left, right) diff --git a/test/runtests.jl b/test/runtests.jl index 1f59a37..4bb8567 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,6 +4,7 @@ using Dates using Statistics import Statistics: mean using Random +using Unitful import IntervalSets: Domain, endpoints, closedendpoints, TypedEndpointsInterval @@ -22,14 +23,16 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed) struct IncompleteInterval <: AbstractInterval{Int} end @testset "IntervalSets" begin - @test isempty(detect_ambiguities(IntervalSets, Base, Core)) + @test isempty(detect_ambiguities(IntervalSets)) @test ordered(2, 1) == (1, 2) @test ordered(1, 2) == (1, 2) @test ordered(Float16(1), 2) == (1, 2) @testset "Basic Closed Sets" begin - @test_throws ArgumentError :a .. "b" + @test_throws ErrorException :a .. "b" + @test_throws ErrorException 1 .. missing + @test_throws ErrorException 1u"m" .. 2u"s" I = 0..3 @test I === ClosedInterval(0,3) === ClosedInterval{Int}(0,3) === Interval(0,3) @@ -139,6 +142,13 @@ struct IncompleteInterval <: AbstractInterval{Int} end @test_throws MethodError duration(1.2..2.4) end + @testset "Unitful interval" begin + @test 1.5u"m" in 1u"m" .. 2u"m" + @test 1500u"μm" in 1u"mm" .. 1u"m" + @test !(500u"μm" in 1u"mm" .. 1u"m") + @test 1u"m" .. 2u"m" == 1000u"mm" .. 2000u"mm" + end + @testset "Day interval" begin A = Date(1990, 1, 1); B = Date(1990, 3, 1) @test width(ClosedInterval(A, B)) == Dates.Day(59) @@ -640,12 +650,6 @@ struct IncompleteInterval <: AbstractInterval{Int} end @test I ∩ (0.0..0.5) === 0.0..0.5 end - @testset "Missing endpoints" begin - # TODO: Remove this testset in the next breaking release (#94) - @test ismissing(2 in 1..missing) - @test_broken ismissing(2 in missing..1) # would be fixed by julialang#31171 - end - @testset "in" begin @test in(0.1, 0.0..1.0) == true @test in(0.0, 0.0..1.0) == true