Skip to content

Commit 39b9007

Browse files
authored
Fix type promotion (#93)
* update type promotion * update tests for type promotion error * update tests around missing * add tests for Unitful interval * update detect_ambiguities not to count ambiguities in Unitful * add tests for 1u"m" .. 2u"s"
1 parent 02d641f commit 39b9007

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/interval.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ mathematical notation, the constructed range is `(left, right)`.
2727
const OpenInterval{T} = Interval{:open,:open,T}
2828

2929
Interval{L,R,T}(i::AbstractInterval) where {L,R,T} = Interval{L,R,T}(endpoints(i)...)
30-
function Interval{L,R}(left, right) where {L,R}
31-
# TODO: Replace the retrun value with `Interval{L,R}(promote(left,right)...)`. (#93)
32-
T = promote_type(typeof(left), typeof(right))
33-
if !isconcretetype(T)
34-
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)
35-
end
36-
Interval{L,R,T}(left,right)
37-
end
30+
Interval{L,R}(left, right) where {L,R} = Interval{L,R}(promote(left,right)...)
3831
Interval{L,R}(left::T, right::T) where {L,R,T} = Interval{L,R,T}(left, right)
3932
Interval(left, right) = ClosedInterval(left, right)
4033

test/runtests.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Dates
44
using Statistics
55
import Statistics: mean
66
using Random
7+
using Unitful
78

89
import IntervalSets: Domain, endpoints, closedendpoints, TypedEndpointsInterval
910

@@ -22,14 +23,16 @@ closedendpoints(I::MyUnitInterval) = (I.isleftclosed,I.isrightclosed)
2223
struct IncompleteInterval <: AbstractInterval{Int} end
2324

2425
@testset "IntervalSets" begin
25-
@test isempty(detect_ambiguities(IntervalSets, Base, Core))
26+
@test isempty(detect_ambiguities(IntervalSets))
2627

2728
@test ordered(2, 1) == (1, 2)
2829
@test ordered(1, 2) == (1, 2)
2930
@test ordered(Float16(1), 2) == (1, 2)
3031

3132
@testset "Basic Closed Sets" begin
32-
@test_throws ArgumentError :a .. "b"
33+
@test_throws ErrorException :a .. "b"
34+
@test_throws ErrorException 1 .. missing
35+
@test_throws ErrorException 1u"m" .. 2u"s"
3336
I = 0..3
3437
@test I === ClosedInterval(0,3) === ClosedInterval{Int}(0,3) ===
3538
Interval(0,3)
@@ -139,6 +142,13 @@ struct IncompleteInterval <: AbstractInterval{Int} end
139142
@test_throws MethodError duration(1.2..2.4)
140143
end
141144

145+
@testset "Unitful interval" begin
146+
@test 1.5u"m" in 1u"m" .. 2u"m"
147+
@test 1500u"μm" in 1u"mm" .. 1u"m"
148+
@test !(500u"μm" in 1u"mm" .. 1u"m")
149+
@test 1u"m" .. 2u"m" == 1000u"mm" .. 2000u"mm"
150+
end
151+
142152
@testset "Day interval" begin
143153
A = Date(1990, 1, 1); B = Date(1990, 3, 1)
144154
@test width(ClosedInterval(A, B)) == Dates.Day(59)
@@ -640,12 +650,6 @@ struct IncompleteInterval <: AbstractInterval{Int} end
640650
@test I (0.0..0.5) === 0.0..0.5
641651
end
642652

643-
@testset "Missing endpoints" begin
644-
# TODO: Remove this testset in the next breaking release (#94)
645-
@test ismissing(2 in 1..missing)
646-
@test_broken ismissing(2 in missing..1) # would be fixed by julialang#31171
647-
end
648-
649653
@testset "in" begin
650654
@test in(0.1, 0.0..1.0) == true
651655
@test in(0.0, 0.0..1.0) == true

0 commit comments

Comments
 (0)