Skip to content

Commit d4ce62a

Browse files
committed
Replace in with issubset
Replace `in(::AbstractInterval, ::AbstractInterval)` with `issubset(::AbstractInterval, ::AbstractInterval)` and define/export `⊆`, `⊇`, `⊈`, and `⊉` Closes #15
1 parent 3e7cc07 commit d4ce62a

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/Intervals.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ using Base.Dates
66
using TimeZones
77
using Compat: AbstractDateTime
88

9+
import Base: , , ,
10+
911
abstract type AbstractInterval{T} end
1012

1113
include("inclusivity.jl")
@@ -30,8 +32,7 @@ export AbstractInterval,
3032
span,
3133
less_than_disjoint,
3234
greater_than_disjoint,
33-
..,
34-
,
35-
35+
.., , , , , ,
36+
3637

3738
end

src/interval.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ true
182182
```
183183
"""
184184
(a, b) = less_than_disjoint(a, b)
185+
# ≪̸(a, b) = !≪(a, b)
185186

186187
"""
187188
≫(a::AbstractInterval, b::AbstractInterval) -> Bool
@@ -199,16 +200,20 @@ true
199200
```
200201
"""
201202
(a, b) = greater_than_disjoint(a, b)
203+
# ≫̸(a, b) = !≫(a, b)
202204

203205
##### SET OPERATIONS #####
204206

205207
Base.isempty(i::AbstractInterval) = LeftEndpoint(i) > RightEndpoint(i)
206208
Base.in(a::T, b::AbstractInterval{T}) where T = !(a b || a b)
207209

208-
function Base.in(a::AbstractInterval{T}, b::AbstractInterval{T}) where T
210+
function Base.issubset(a::AbstractInterval{T}, b::AbstractInterval{T}) where T
209211
return LeftEndpoint(a) LeftEndpoint(b) && RightEndpoint(a) RightEndpoint(b)
210212
end
211213

214+
Base.:(a::AbstractInterval{T}, b::AbstractInterval{T}) where T = !issubset(a, b)
215+
Base.:(a::AbstractInterval{T}, b::AbstractInterval{T}) where T = !issubset(b, a)
216+
212217
# Should probably define union, too. There is power in a union.
213218

214219
function Base.intersect(a::AbstractInterval{T}, b::AbstractInterval{T}) where T

test/interval.jl

+18-8
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,25 @@
322322
@test in(b - unit, interval)
323323
@test !in(b + unit, interval)
324324
end
325+
end
325326

326-
@test in(0..10, 0..10)
327-
@test in(Interval(0, 10, false, false), 0..10)
328-
@test !in(0..10, Interval(0, 10, false, false))
329-
@test in(1..9, 0..10)
330-
@test !in(0..10, 1..9)
331-
@test !in(1..11, 0..10)
332-
@test !in(-1..9, 0..10)
333-
@test !in(20..30, 0..10)
327+
@testset "issubset" begin
328+
@test 0..10 0..10
329+
@test 0..10 0..10
330+
@test Interval(0, 10, false, false) 0..10
331+
@test Interval(0, 10, false, false) 0..10
332+
@test 0..10 Interval(0, 10, false, false)
333+
@test 0..10 Interval(0, 10, false, false)
334+
@test 1..9 0..10
335+
@test 1..9 0..10
336+
@test 0..10 1..9
337+
@test 0..10 1..9
338+
@test 1..11 0..10
339+
@test 1..11 0..10
340+
@test -1..9 0..10
341+
@test -1..9 0..10
342+
@test 20..30 0..10
343+
@test 20..30 0..10
334344
end
335345

336346
@testset "intersect" begin

0 commit comments

Comments
 (0)