Skip to content

Commit 021cf45

Browse files
authored
Add isdisjoint (#105)
* add Base.isdisjoint(a::Domain, b::Domain) * add tests for Base.isdisjoint(a::Domain, b::Domain)
1 parent d54ee11 commit 021cf45

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/IntervalSets.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A subtype of `Domain{T}` represents a subset of type `T`, that provides `in`.
2222
abstract type Domain{T} end
2323

2424
Base.IteratorSize(::Type{<:Domain}) = Base.SizeUnknown()
25-
25+
Base.isdisjoint(a::Domain, b::Domain) = isempty(a b)
2626

2727
"""
2828
A subtype of `AbstractInterval{T}` represents an interval subset of type `T`, that provides

test/runtests.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end
423423
@test OpenInterval(i1) Interval{:closed,:open}(i2) Interval{:closed,:open}(i2) OpenInterval(i1) Interval{:closed,:open}(i2)
424424
@test Interval{:open,:closed}(i1) OpenInterval(i2) OpenInterval(i2) Interval{:open,:closed}(i1) OpenInterval(i2)
425425
@test Interval{:open,:closed}(i1) Interval{:closed,:open}(i2) Interval{:closed,:open}(i2) Interval{:open,:closed}(i1) Interval{:closed,:open}(i2)
426+
@test !isdisjoint(i1, i2)
426427

427428

428429
# - union of partially overlapping intervals
@@ -462,6 +463,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end
462463
@test OpenInterval(i1) Interval{:closed,:open}(i3) Interval{:closed,:open}(i3) OpenInterval(i1) Interval{:closed,:open}(d)
463464
@test Interval{:open,:closed}(i1) OpenInterval(i3) OpenInterval(i3) Interval{:open,:closed}(i1) Interval{:open,:closed}(d)
464465
@test Interval{:open,:closed}(i1) Interval{:closed,:open}(i3) Interval{:closed,:open}(i3) Interval{:open,:closed}(i1) d
466+
@test !isdisjoint(i1, i3)
465467

466468

467469
# - union of barely overlapping intervals
@@ -524,6 +526,11 @@ struct IncompleteInterval <: AbstractInterval{Int} end
524526
@test isempty(OpenInterval(i1) i4)
525527
@test isempty(i1 OpenInterval(i4))
526528
@test isempty(Interval{:closed,:open}(i1) i4)
529+
@test isdisjoint(i1, i4)
530+
@test isdisjoint(i4, i1)
531+
@test isdisjoint(OpenInterval(i1), i4)
532+
@test isdisjoint(i1, OpenInterval(i4))
533+
@test isdisjoint(Interval{:closed,:open}(i1), i4)
527534

528535

529536
# - intersection of almost-overlapping intervals
@@ -532,6 +539,11 @@ struct IncompleteInterval <: AbstractInterval{Int} end
532539
@test isempty(OpenInterval(i1) i5)
533540
@test isempty(i1 OpenInterval(i5))
534541
@test isempty(Interval{:closed,:open}(i1) i5)
542+
@test isdisjoint(i1, i5)
543+
@test isdisjoint(i5, i1)
544+
@test isdisjoint(OpenInterval(i1), i5)
545+
@test isdisjoint(i1, OpenInterval(i5))
546+
@test isdisjoint(Interval{:closed,:open}(i1), i5)
535547

536548
# - union of interval with empty
537549
@test i1 i_empty i_empty i1 i1
@@ -556,6 +568,11 @@ struct IncompleteInterval <: AbstractInterval{Int} end
556568
@test isempty(OpenInterval(i1) i_empty)
557569
@test isempty(i1 OpenInterval(i_empty))
558570
@test isempty(Interval{:closed,:open}(i1) i_empty)
571+
@test isdisjoint(i1, i_empty)
572+
@test isdisjoint(i_empty, i1)
573+
@test isdisjoint(OpenInterval(i1), i_empty)
574+
@test isdisjoint(i1, OpenInterval(i_empty))
575+
@test isdisjoint(Interval{:closed,:open}(i1), i_empty)
559576

560577
# - test matching endpoints
561578
@test (0..1) OpenInterval(0..1) OpenInterval(0..1) (0..1) 0..1

0 commit comments

Comments
 (0)