Skip to content

Commit

Permalink
Equality for Non-ordered anchored intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Aug 14, 2018
1 parent 9f0fa69 commit 400d570
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/anchoredinterval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ end

##### EQUALITY #####

function Base.:(==)(a::AnchoredInterval{P, T}, b::AnchoredInterval{P, T}) where {P, T}
return anchor(a) == anchor(b) && inclusivity(a) == inclusivity(b)
end

# Required for min/max of AnchoredInterval{LaxZonedDateTime} when the anchor is AMB or DNE
function Base.isless(a::AnchoredInterval{P, T}, b::AnchoredInterval{P, T}) where {P, T}
return (
Expand Down
18 changes: 11 additions & 7 deletions test/anchoredinterval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ using Intervals: canonicalize
end

@testset "non-ordered" begin
interval = AnchoredInterval{-Inf}(Inf)
@test isequal(first(interval), NaN)
@test isequal(last(interval), Inf)

interval = AnchoredInterval{Inf}(-Inf)
@test isequal(first(interval), -Inf)
@test isequal(last(interval), NaN)
ending = AnchoredInterval{-Inf}(Inf)
@test isequal(first(ending), NaN)
@test isequal(last(ending), Inf)
@test ending == ending
@test isequal(ending, ending)

beginning = AnchoredInterval{Inf}(-Inf)
@test isequal(first(beginning), -Inf)
@test isequal(last(beginning), NaN)
@test beginning == beginning
@test isequal(beginning, beginning)
end

@testset "hash" begin
Expand Down

0 comments on commit 400d570

Please sign in to comment.