diff --git a/src/deprecated.jl b/src/deprecated.jl index e6c370b..16efbb7 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -1,202 +1,5 @@ using Base: @deprecate, depwarn -import Dates: Date, DateTime -# BEGIN Intervals 1.X.Y deprecations +# BEGIN Intervals 2.X.Y deprecations -export Inclusivity, inclusivity -include("inclusivity.jl") - -@deprecate Date(interval::Interval{Date}) convert(Date, interval) -@deprecate DateTime(interval::Interval{DateTime}) convert(DateTime, interval) -@deprecate Date(interval::AnchoredInterval{P, Date} where P) convert(Date, interval) -@deprecate DateTime(interval::AnchoredInterval{P, DateTime} where P) convert(DateTime, interval) - - -function Endpoint{T,D}(ep::T, included::Bool) where {T,D} - B = bound_type(included) - depwarn("`Endpoint{T,D}(ep, $included)` is deprecated, use `Endpoint{T,D,$(repr(B))}(ep)` instead.", :Endpoint) - return Endpoint{T,D,B}(ep) -end - -function LeftEndpoint(ep, included::Bool) - B = bound_type(included) - depwarn("`LeftEndpoint(ep, $included)` is deprecated, use `LeftEndpoint{$(repr(B))}(ep)` instead.", :LeftEndpoint) - return LeftEndpoint{B}(ep) -end - -function RightEndpoint(ep, included::Bool) - B = bound_type(included) - depwarn("`RightEndpoint(ep, $included)` is deprecated, use `RightEndpoint{$(repr(B))}(ep)` instead.", :RightEndpoint) - return RightEndpoint{B}(ep) -end - -# intervals.jl -function Interval{T,L,R}(f::T, l::T, inc::Inclusivity) where {T,L,R} - left_inc = bound_type(first(inc)) - right_inc = bound_type(last(inc)) - if L !== left_inc || R !== right_inc - throw(ArgumentError("Specified inclusivity ($(repr(left_inc)), $(repr(right_inc))) doesn't match bound types ($(repr(L)), $(repr(R)))")) - end - depwarn("`Interval{T,$(repr(L)),$(repr(R))}(f, l, $(repr(inc)))` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval) - return Interval{T,L,R}(f, l) -end - -function Interval{T,L,R}(f, l, inc::Inclusivity) where {T,L,R} - # Using depwarn from next call - return Interval{T,L,R}(convert(T, f), convert(T, l), inc) -end - -function Interval{T}(f, l, inc::Inclusivity) where T - L = bound_type(first(inc)) - R = bound_type(last(inc)) - depwarn("`Interval{T}(f, l, $(repr(inc)))` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval) - return Interval{T,L,R}(f, l) -end - -function Interval{T}(f, l, x::Bool, y::Bool) where T - L = bound_type(x) - R = bound_type(y) - depwarn("`Interval{T}(f, l, $x, $y)` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval) - return Interval{T,L,R}(f, l) -end - -function Interval(f, l, inc::Inclusivity) - L = bound_type(first(inc)) - R = bound_type(last(inc)) - depwarn("`Interval(f, l, $(repr(inc)))` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval) - return Interval{L,R}(f, l) -end - -function Interval(f, l, x::Bool, y::Bool) - L = bound_type(x) - R = bound_type(y) - depwarn("`Interval(f, l, $x, $y)` is deprecated, use `Interval{T,$(repr(L)),$(repr(R))}(f, l)` instead.", :Interval) - return Interval{L,R}(f, l) -end - -function inclusivity(interval::AbstractInterval{T,L,R}) where {T,L,R} - depwarn("`inclusivity(interval)` is deprecated and has no direct replacement. See `bounds_types(interval)` for similar functionality.", :inclusivity) - return Inclusivity(L === Closed, R === Closed; ignore_depwarn=true) -end - -# anchoredintervals.jl -function AnchoredInterval{P,T,L,R}(anchor::T, inc::Inclusivity) where {P,T,L,R} - left_inc = bound_type(first(inc)) - right_inc = bound_type(last(inc)) - if L !== left_inc || R !== right_inc - throw(ArgumentError("Specified inclusivity ($(repr(left_inc)), $(repr(right_inc))) doesn't match bound types ($(repr(L)), $(repr(R)))")) - end - depwarn("`AnchoredInterval{P,T,$(repr(L)),$(repr(R))}(anchor, $(repr(inc)))` is deprecated, use `AnchoredInterval{P,T,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval) - return AnchoredInterval{P,T,L,R}(anchor) -end - -function AnchoredInterval{P,T,L,R}(anchor, inc::Inclusivity) where {P,T,L,R} - # Using depwarn from next call - return AnchoredInterval{P,T,L,R}(convert(T, anchor), inc) -end - -function AnchoredInterval{P,T}(anchor, inc::Inclusivity) where {P,T} - L = bound_type(first(inc)) - R = bound_type(last(inc)) - depwarn("`AnchoredInterval{P,T}(anchor, $(repr(inc)))` is deprecated, use `AnchoredInterval{P,T,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval) - return AnchoredInterval{P,T,L,R}(anchor) -end - -function AnchoredInterval{P,T}(anchor, x::Bool, y::Bool) where {P,T} - L = bound_type(x) - R = bound_type(y) - depwarn("`AnchoredInterval{P,T}(anchor, $x, $y)` is deprecated, use `AnchoredInterval{P,T,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval) - return AnchoredInterval{P,T,L,R}(anchor) -end - -function AnchoredInterval{P}(anchor, inc::Inclusivity) where P - L = bound_type(first(inc)) - R = bound_type(last(inc)) - depwarn("`AnchoredInterval{P}(anchor, $(repr(inc)))` is deprecated, use `AnchoredInterval{P,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval) - return AnchoredInterval{P,L,R}(anchor) -end - -function AnchoredInterval{P}(anchor, x::Bool, y::Bool) where P - L = bound_type(x) - R = bound_type(y) - depwarn("`AnchoredInterval{P}(anchor, $x, $y)` is deprecated, use `AnchoredInterval{P,$(repr(L)),$(repr(R))}(anchor)` instead.", :AnchoredInterval) - return AnchoredInterval{P,L,R}(anchor) -end - -function HourEnding(anchor, x::Bool, y::Bool) - L = bound_type(x) - R = bound_type(y) - depwarn("`HourEnding(anchor, $x, $y)` is deprecated, use `HourEnding{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourEnding) - return HourEnding{L,R}(anchor) -end - -function HourEnding(anchor, inc::Inclusivity) - L = bound_type(first(inc)) - R = bound_type(last(inc)) - depwarn("`HourEnding(anchor, $(repr(inc)))` is deprecated, use `HourEnding{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourEnding) - return HourEnding{L,R}(anchor) -end - -function HourBeginning(anchor, x::Bool, y::Bool) - L = bound_type(x) - R = bound_type(y) - depwarn("`HourBeginning(anchor, $x, $y)` is deprecated, use `HourBeginning{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourBeginning) - return HourBeginning{L,R}(anchor) -end - -function HourBeginning(anchor, inc::Inclusivity) - L = bound_type(first(inc)) - R = bound_type(last(inc)) - depwarn("`HourBeginning(anchor, $(repr(inc)))` is deprecated, use `HourBeginning{$(repr(L)),$(repr(R))}(anchor)` instead.", :HourBeginning) - return HourBeginning{L,R}(anchor) -end - -function HE(anchor, x::Bool, y::Bool) - L = bound_type(x) - R = bound_type(y) - if !x && y - depwarn("`HE(anchor, $x, $y)` is deprecated, use `HE(anchor)` instead.", :HE) - else - depwarn("`HE(anchor, $x, $y)` is deprecated, use `HourEnding{$(repr(L)),$(repr(R))}(ceil(anchor, Hour))` instead.", :HE) - end - return HourEnding{L,R}(ceil(anchor, Hour)) -end - -function HE(anchor, inc::Inclusivity) - L = bound_type(first(inc)) - R = bound_type(last(inc)) - if !first(inc) && last(inc) - depwarn("`HE(anchor, $(repr(inc)))` is deprecated, use `HE(anchor)` instead.", :HE) - else - depwarn("`HE(anchor, $(repr(inc)))` is deprecated, use `HourEnding{$(repr(L)),$(repr(R))}(ceil(anchor, Hour))` instead.", :HE) - end - return HourEnding{L,R}(ceil(anchor, Hour)) -end - -function HB(anchor, x::Bool, y::Bool) - L = bound_type(x) - R = bound_type(y) - if x && !y - depwarn("`HB(anchor, $x, $y)` is deprecated, use `HB(anchor)` instead.", :HB) - else - depwarn("`HB(anchor, $x, $y)` is deprecated, use `HourBeginning{$(repr(L)),$(repr(R))}(floor(anchor, Hour))` instead.", :HB) - end - return HourBeginning{L,R}(floor(anchor, Hour)) -end - -function HB(anchor, inc::Inclusivity) - L = bound_type(first(inc)) - R = bound_type(last(inc)) - if first(inc) && !last(inc) - depwarn("`HB(anchor, $(repr(inc)))` is deprecated, use `HB(anchor)` instead.", :HB) - else - depwarn("`HB(anchor, $(repr(inc)))` is deprecated, use `HourBeginning{$(repr(L)),$(repr(R))}(floor(anchor, Hour))` instead.", :HB) - end - return HourBeginning{L,R}(floor(anchor, Hour)) -end - -@deprecate union(intervals::AbstractVector{<:AbstractInterval}) convert(Vector, union(IntervalSet(intervals))) -@deprecate union!(intervals::AbstractVector{<:AbstractInterval}) convert(Vector, union!(IntervalSet(intervals))) -@deprecate superset(intervals::AbstractVector{<:AbstractInterval}) superset(IntervalSet(intervals)) - -# END Intervals 1.X.Y deprecations +# END Intervals 2.X.Y deprecations diff --git a/src/inclusivity.jl b/src/inclusivity.jl deleted file mode 100644 index 72199f9..0000000 --- a/src/inclusivity.jl +++ /dev/null @@ -1,85 +0,0 @@ -""" - Inclusivity(first::Bool, last::Bool) -> Inclusivity - -Defines whether an `AbstractInterval` is open, half-open, or closed. -""" - -struct Inclusivity - first::Bool - last::Bool - - function Inclusivity(first::Bool, last::Bool; ignore_depwarn::Bool=false) - if !ignore_depwarn - depwarn( - "`Inclusivity(::Bool, ::Bool)` is deprecated and has no direct replacement. " * - "See `Interval` or `AnchoredInterval` constructors for alternatives.", - :Inclusivity, - ) - end - return new(first, last) - end -end - -""" - Inclusivity(i::Integer) -> Inclusivity - -Defines whether an interval is open, half-open, or closed, using an integer code: - -### Inclusivity Values - -* `0`: Neither endpoint is included (the `AbstractInterval` is open) -* `1`: Only the lesser endpoint is included (the `AbstractInterval` is left-closed) -* `2`: Only the greater endpoint is included (the `AbstractInterval` is right-closed) -* `3`: Both endpoints are included (the `AbstractInterval` is closed) - -Note that this constructor does not perform bounds-checking: instead it checks the values -of the two least-significant bits of the integer. This means that `Inclusivity(5)` is -equivalent to `Inclusivity(1)`. -""" - -function Inclusivity(i::Integer) - depwarn( - "`Inclusivity(::Integer)` is deprecated and has no direct replacement. " * - "See `Interval` or `AnchoredInterval` constructors for alternatives.", - :Inclusivity, - ) - return Inclusivity(i & 0b01 > 0, i & 0b10 > 0; ignore_depwarn=true) -end - -function Base.copy(x::Inclusivity) - depwarn( - "`copy(::Inclusivity)` is deprecated and has no direct replacement. " * - "See `Interval` or `AnchoredInterval` constructors for alternatives.", - :copy, - ) - return Inclusivity(x.first, x.last; ignore_depwarn=true) -end - -function Base.convert(::Type{I}, x::Inclusivity) where I <: Integer - return I(x.last << 1 + x.first) -end - -Base.broadcastable(i::Inclusivity) = Ref(i) - -Base.first(x::Inclusivity) = x.first -Base.last(x::Inclusivity) = x.last - -isclosed(x::Inclusivity) = first(x) && last(x) -Base.isopen(x::Inclusivity) = !(first(x) || last(x)) - -Base.isless(a::Inclusivity, b::Inclusivity) = isless(convert(Int, a), convert(Int, b)) - -function Base.show(io::IO, x::T) where T <: Inclusivity - if get(io, :compact, false) - print(io, x) - else - print(io, "$T($(x.first), $(x.last))") - end -end - -function Base.print(io::IO, x::Inclusivity) - open_char = first(x) ? '[' : '(' - close_char = last(x) ? ']' : ')' - desc = isclosed(x) ? "Closed" : isopen(x) ? "Open" : first(x) ? "Left" : "Right" - print(io, "Inclusivity ", open_char, desc, close_char) -end diff --git a/test/anchoredinterval.jl b/test/anchoredinterval.jl index 183d93a..2209896 100644 --- a/test/anchoredinterval.jl +++ b/test/anchoredinterval.jl @@ -32,14 +32,6 @@ using Intervals: Bounded, Ending, Beginning, canonicalize, isunbounded # Non-period AnchoredIntervals @test AnchoredInterval{-10}(10) isa AnchoredInterval @test AnchoredInterval{25}('a') isa AnchoredInterval - - # Deprecated - @test_deprecated AnchoredInterval{Hour(-1),DateTime,Open,Closed}(dt, Inclusivity(false, true)) - @test_throws ArgumentError AnchoredInterval{Hour(-1),DateTime,Open,Closed}(dt, Inclusivity(true, true)) - - @test_deprecated AnchoredInterval{-1,Float64,Open,Closed}(0, Inclusivity(false, true)) - @test_throws ArgumentError AnchoredInterval{-1,Float64,Open,Closed}(0, Inclusivity(true, true)) - @test_throws MethodError AnchoredInterval{-1,Float64,Open,Closed}(nothing, Inclusivity(false, true)) end @testset "zero-span" begin @@ -774,21 +766,6 @@ using Intervals: Bounded, Ending, Beginning, canonicalize, isunbounded @test timezone(aiutc) == tz"UTC" end - @testset "legacy deserialization" begin - # Serialized string generated on Intervals@1.2 with: - # `julia --project -E 'using Serialization, Intervals; sprint(serialize, AnchoredInterval{-1,Int}(2, true, false))'`. - buffer = IOBuffer( - SERIALIZED_HEADER * - "\x004\x10\x01\x10AnchoredInterval\x1f\v՞\x84\xec\xf7-`\x87\xbb" * - "S\xe1Á\x88A\xd8\x01\tIntervalsD\x02\0\0\x001\xff\xff\xff\xff\0\b\xe14\x10" * - "\x01\vInclusivity\x1f\v՞\x84\xec\xf7-`\x87\xbbS\xe1Á\x88A\xd8,\x02\0DML" - ) - - interval = deserialize(buffer) - @test interval isa AnchoredInterval - @test interval == AnchoredInterval{-1,Int,Closed,Open}(2) - end - @testset "floor" begin # only :anchor, :left, and :right are supported @test_throws ArgumentError floor(AnchoredInterval{-0.5}(1.0); on=:nothing) diff --git a/test/comparisons.jl b/test/comparisons.jl index 2c8b131..1b34976 100644 --- a/test/comparisons.jl +++ b/test/comparisons.jl @@ -78,7 +78,7 @@ end @test !overlaps(earlier, later) @test !contiguous(earlier, later) @test_throws ArgumentError merge(earlier, later) - @test superset([earlier, later]) == expected_superset + @test superset(IntervalSet([earlier, later])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(earlier, later) @@ -87,8 +87,6 @@ end @test_throws MethodError setdiff(later, earlier) @test_throws MethodError symdiff(earlier, later) - # Using a vector of intervals as sets - @test union([earlier, later]) == [earlier, later] @test union(IntervalSet([earlier, later])) == IntervalSet([earlier, later]) # TODO: These functions should be compatible with unbounded intervals @@ -165,7 +163,7 @@ end @test !overlaps(earlier, later) @test !contiguous(earlier, later) @test_throws ArgumentError merge(earlier, later) - @test superset([earlier, later]) == expected_superset + @test superset(IntervalSet([earlier, later])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(earlier, later) @@ -174,8 +172,6 @@ end @test_throws MethodError setdiff(later, earlier) @test_throws MethodError symdiff(earlier, later) - # Using a vector of intervals as sets - @test union([earlier, later]) == [earlier, later] @test union(IntervalSet([earlier, later])) == IntervalSet([earlier, later]) # TODO: These functions should be compatible with unbounded intervals @@ -252,7 +248,7 @@ end @test !overlaps(earlier, later) @test contiguous(earlier, later) @test merge(earlier, later) == expected_superset - @test superset([earlier, later]) == expected_superset + @test superset(IntervalSet([earlier, later])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(earlier, later) @@ -261,8 +257,6 @@ end @test_throws MethodError setdiff(later, earlier) @test_throws MethodError symdiff(earlier, later) - # Using a vector of intervals as sets - @test union([earlier, later]) == [expected_superset] @test union(IntervalSet([earlier, later])) == IntervalSet([expected_superset]) # TODO: These functions should be compatible with unbounded intervals @@ -280,7 +274,7 @@ end @test setdiff(IntervalSet(later), IntervalSet(earlier)) == IntervalSet(expected_xor[2:2]) # TODO: Sometimes expected_xor would get mutated in this call - @test symdiff([earlier], [later]) == expected_xor != union(expected_xor) + @test symdiff([earlier], [later]) == expected_xor == union(expected_xor) @test symdiff(IntervalSet(earlier), IntervalSet(later)) == union(IntervalSet(expected_xor)) end end @@ -341,7 +335,7 @@ end @test !overlaps(earlier, later) @test contiguous(earlier, later) @test merge(earlier, later) == expected_superset - @test superset([earlier, later]) == expected_superset + @test superset(IntervalSet([earlier, later])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(earlier, later) @@ -350,8 +344,6 @@ end @test_throws MethodError setdiff(later, earlier) @test_throws MethodError symdiff(earlier, later) - # Using a vector of intervals as sets - @test union([earlier, later]) == [expected_superset] @test union(IntervalSet([earlier, later])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -368,7 +360,7 @@ end @test setdiff([later], [earlier]) == expected_xor[2:2] @test setdiff(IntervalSet(later), IntervalSet(earlier)) == IntervalSet(expected_xor[2:2]) - @test symdiff([earlier], [later]) == expected_xor != union(expected_xor) + @test symdiff([earlier], [later]) == expected_xor == union(expected_xor) @test symdiff(IntervalSet(earlier), IntervalSet(later)) == union(IntervalSet(expected_xor)) end end @@ -433,7 +425,7 @@ end @test overlaps(earlier, later) @test !contiguous(earlier, later) @test merge(earlier, later) == expected_superset - @test superset([earlier, later]) == expected_superset + @test superset(IntervalSet([earlier, later])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(earlier, later) @@ -442,8 +434,6 @@ end @test_throws MethodError setdiff(later, earlier) @test_throws MethodError symdiff(earlier, later) - # Using a vector of intervals as sets - @test union([earlier, later]) == [expected_superset] @test union(IntervalSet([earlier, later])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -526,7 +516,7 @@ end @test overlaps(earlier, later) @test !contiguous(earlier, later) @test merge(earlier, later) == expected_superset - @test superset([earlier, later]) == expected_superset + @test superset(IntervalSet([earlier, later])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(earlier, later) @@ -535,8 +525,6 @@ end @test_throws MethodError setdiff(later, earlier) @test_throws MethodError symdiff(earlier, later) - # Using a vector of intervals as sets - @test union([earlier, later]) == [expected_superset] @test union(IntervalSet([earlier, later])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -601,7 +589,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -610,8 +598,6 @@ end @test_throws MethodError setdiff(b, a) @test_throws MethodError symdiff(a, b) - # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -676,7 +662,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -685,8 +671,6 @@ end @test_throws MethodError setdiff(b, a) @test_throws MethodError symdiff(a, b) - # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -754,7 +738,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -763,8 +747,6 @@ end @test_throws MethodError setdiff(b, a) @test_throws MethodError symdiff(a, b) - # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -836,7 +818,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -845,8 +827,6 @@ end @test_throws MethodError setdiff(b, a) @test_throws MethodError symdiff(a, b) - # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -916,7 +896,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -925,8 +905,6 @@ end @test_throws MethodError setdiff(b, a) @test_throws MethodError symdiff(a, b) - # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -994,7 +972,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -1004,7 +982,6 @@ end @test_throws MethodError symdiff(a, b) # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet(a), IntervalSet(b)) == IntervalSet(expected_superset) @test intersect([a], [b]) != [expected_overlap] @test_broken intersect(IntervalSet([a, b])) == IntervalSet(expected_overlap) # Internal type issue @@ -1071,7 +1048,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -1080,8 +1057,6 @@ end @test_throws MethodError setdiff(b, a) @test_throws MethodError symdiff(a, b) - # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -1146,7 +1121,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -1155,8 +1130,6 @@ end @test_throws MethodError setdiff(b, a) @test_throws MethodError symdiff(a, b) - # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -1221,7 +1194,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -1230,8 +1203,6 @@ end @test_throws MethodError setdiff(b, a) @test_throws MethodError symdiff(a, b) - # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -1294,7 +1265,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -1303,8 +1274,6 @@ end @test_throws MethodError setdiff(b, a) @test_throws MethodError symdiff(a, b) - # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals @@ -1359,7 +1328,7 @@ end @test overlaps(a, b) @test !contiguous(a, b) @test merge(a, b) == expected_superset - @test superset([a, b]) == expected_superset + @test superset(IntervalSet([a, b])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -1368,8 +1337,6 @@ end @test_throws MethodError setdiff(b, a) @test_throws MethodError symdiff(a, b) - # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union([a], [b]) == [a, b] != [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) @@ -1453,7 +1420,7 @@ end @test overlaps(smaller, larger) @test !contiguous(smaller, larger) @test merge(a, b) == expected_superset - @test superset([smaller, larger]) == expected_superset + @test superset(IntervalSet([smaller, larger])) == expected_superset # Intervals acting as sets. Functions should return a single interval @test_throws MethodError union(a, b) @@ -1463,7 +1430,6 @@ end @test_throws MethodError symdiff(a, b) # Using a vector of intervals as sets - @test union([a, b]) == [expected_superset] @test union(IntervalSet([a, b])) == IntervalSet(expected_superset) # TODO: These functions should be compatible with unbounded intervals diff --git a/test/inclusivity.jl b/test/inclusivity.jl deleted file mode 100644 index 6051d9d..0000000 --- a/test/inclusivity.jl +++ /dev/null @@ -1,91 +0,0 @@ -Inclusivity(args...) = @test_deprecated Intervals.Inclusivity(args...) - -@testset "Inclusivity" begin - @testset "constructor" begin - for (s, f) in [(false, false), (false, true), (true, false), (true, true)] - inc = Inclusivity(s, f) - @test (first(inc), last(inc)) == (s, f) - end - - @test Inclusivity(0) == Inclusivity(false, false) - @test Inclusivity(1) == Inclusivity(true, false) - @test Inclusivity(2) == Inclusivity(false, true) - @test Inclusivity(3) == Inclusivity(true, true) - end - - @testset "accessors" begin - inc = Inclusivity(false, false) - @test !first(inc) - @test !last(inc) - @test isopen(inc) - @test !isclosed(inc) - - inc = Inclusivity(false, true) - @test !first(inc) - @test last(inc) - @test !isopen(inc) - @test !isclosed(inc) - - inc = Inclusivity(true, true) - @test first(inc) - @test last(inc) - @test !isopen(inc) - @test isclosed(inc) - end - - @testset "convert" begin - for i in 0:3 - for T in [UInt8, UInt32, Int32, Int64] - @test convert(T, Inclusivity(i)) == T(i) - end - end - end - - @testset "equality" begin - inc = Inclusivity(false, true) - cp = @test_deprecated copy(inc) - diff = Inclusivity(true, false) - @test isequal(inc, cp) - @test hash(inc) == hash(cp) - @test !isequal(inc, diff) - @test hash(inc) != hash(diff) - - # Verify that Inclusivity is treated as a scalar during broadcast - @test size(Inclusivity(false, true) .== Inclusivity(false, true)) == () - end - - @testset "display" begin - inc = Inclusivity(false, false) - @test string(inc) == "Inclusivity (Open)" - @test sprint(show, inc, context=:compact=>true) == string(inc) - @test sprint(show, inc) == "$(Intervals.Inclusivity)(false, false)" - - inc = Inclusivity(false, true) - @test string(inc) == "Inclusivity (Right]" - @test sprint(show, inc, context=:compact=>true) == string(inc) - @test sprint(show, inc) == "$(Intervals.Inclusivity)(false, true)" - - inc = Inclusivity(true, false) - @test string(inc) == "Inclusivity [Left)" - @test sprint(show, inc, context=:compact=>true) == string(inc) - @test sprint(show, inc) == "$(Intervals.Inclusivity)(true, false)" - - inc = Inclusivity(true, true) - @test string(inc) == "Inclusivity [Closed]" - @test sprint(show, inc, context=:compact=>true) == string(inc) - @test sprint(show, inc) == "$(Intervals.Inclusivity)(true, true)" - end - - @testset "isless" begin - @test isless(Inclusivity(0), Inclusivity(1)) - @test isless(Inclusivity(1), Inclusivity(2)) - @test isless(Inclusivity(2), Inclusivity(3)) - @test !isless(Inclusivity(0), Inclusivity(0)) - @test !isless(Inclusivity(1), Inclusivity(0)) - end - - @testset "sort" begin - @test sort(map(Inclusivity, 0:3)) == map(Inclusivity, 0:3) - @test sort(map(Inclusivity, 3:-1:0)) == map(Inclusivity, 0:3) - end -end diff --git a/test/interval.jl b/test/interval.jl index ad0dc98..6e3f138 100644 --- a/test/interval.jl +++ b/test/interval.jl @@ -67,16 +67,6 @@ @test_throws MethodError Interval{Int, Unbounded, Closed}(1, 2) @test_throws MethodError Interval{Int, Closed, Unbounded}(1, 2) @test_throws MethodError Interval{Int, Unbounded, Unbounded}(1, 2) - - # Deprecated - @test_deprecated Interval{DateTime,Open,Closed}(DateTime(0), DateTime(0), Inclusivity(false, true)) - @test_throws ArgumentError Interval{DateTime,Open,Closed}(DateTime(0), DateTime(0), Inclusivity(true, true)) - - @test_deprecated Interval{Float64,Open,Closed}(0, 0, Inclusivity(false, true)) - @test_throws ArgumentError Interval{Float64,Open,Closed}(0, 0, Inclusivity(true, true)) - @test_throws MethodError Interval{Float64,Unbounded,Closed}(nothing, 0, Inclusivity(true, true)) - @test_throws MethodError Interval{Float64,Open,Unbounded}(0, nothing, Inclusivity(false, true)) - @test_throws ArgumentError Interval{Nothing,Unbounded,Unbounded}(nothing, nothing, Inclusivity(false, false)) end @testset "non-ordered" begin @@ -751,57 +741,42 @@ end @testset "union" begin - intervals = [ + intervals = IntervalSet([ Interval{Open, Open}(-100, -1), Interval{Open, Open}(-10, -1), Interval{Open, Open}(10, 15), Interval{Open, Open}(13, 20), - ] - expected = [ + ]) + expected = IntervalSet([ Interval{Open, Open}(-100, -1), Interval{Open, Open}(10, 20), - ] + ]) @test union(intervals) == expected # Ordering - intervals = [ + intervals = IntervalSet([ Interval{Open, Open}(-100, -1), Interval{Open, Open}(10, 15), Interval{Open, Open}(-10, -1), Interval{Open, Open}(13, 20), - ] + ]) @test union(intervals) == expected - @test intervals == [ + @test intervals == IntervalSet([ Interval{Open, Open}(-100, -1), Interval{Open, Open}(10, 15), Interval{Open, Open}(-10, -1), Interval{Open, Open}(13, 20), - ] + ]) @test union!(intervals) == expected @test intervals == expected # Mixing bounds - intervals = [ + intervals = IntervalSet([ Interval{Open, Open}(-100, -1), Interval{Closed, Closed}(-10, -1) - ] - @test union(intervals) == [Interval{Open, Closed}(-100, -1)] - end - - @testset "legacy deserialization" begin - # Serialized string generated on Intervals@1.2 with: - # `julia --project -E 'using Serialization, Intervals; sprint(serialize, Interval(1, 2, true, false))'`. - buffer = IOBuffer( - SERIALIZED_HEADER * - "\x004\x10\x01\bInterval\x1f\v՞\x84\xec\xf7-`\x87\xbbS\xe1Á\x88A\xd8\x01\t" * - "IntervalsD\x01\0\0\0\0\b\xe0\xe14\x10\x01\vInclusivity\x1f\v՞\x84\xec\xf7" * - "-`\x87\xbbS\xe1Á\x88A\xd8,\x02\0DML" - ) - - interval = deserialize(buffer) - @test interval isa Interval - @test interval == Interval{Closed,Open}(1, 2) + ]) + @test union(intervals) == IntervalSet(Interval{Open, Closed}(-100, -1)) end @testset "parse" begin diff --git a/test/runtests.jl b/test/runtests.jl index f622a57..abb4b1b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -14,7 +14,6 @@ const BOUND_PERMUTATIONS = product((Closed, Open), (Closed, Open)) include("test_utils.jl") @testset "Intervals" begin - include("inclusivity.jl") include("endpoint.jl") include("interval.jl") include("anchoredinterval.jl")