Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isless and make isequal consistent with hash #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/IntervalSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __precompile__()
module IntervalSets

using Base: @pure
import Base: eltype, convert, show, in, length, isempty, isequal, issubset, ==, hash,
import Base: eltype, convert, show, in, length, isempty, isequal, isless, issubset, ==, hash,
union, intersect, minimum, maximum, extrema, range, ⊇

using Compat
Expand Down
4 changes: 3 additions & 1 deletion src/closed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ in(a::ClosedInterval, b::ClosedInterval) = (b.left <= a.left) & (a.right <= b.ri

isempty(A::ClosedInterval) = A.left > A.right

isequal(A::ClosedInterval, B::ClosedInterval) = (isequal(A.left, B.left) & isequal(A.right, B.right)) | (isempty(A) & isempty(B))
isequal(A::ClosedInterval, B::ClosedInterval) = isequal(A.left, B.left) & isequal(A.right, B.right)

isless(A::ClosedInterval, B::ClosedInterval) = isless(A.left, B.left) | (isequal(A.left, B.left) & isless(A.right, B.right))

==(A::ClosedInterval, B::ClosedInterval) = (A.left == B.left && A.right == B.right) || (isempty(A) && isempty(B))

Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ using Compat.Dates
@test J == J
@test L == L
@test isequal(I, I)
@test isequal(J, K)
@test !isequal(J, K)
@test !isless(I, I)
@test isless(I, J)
@test !isless(J, I)
@test isless(I, 0..4)

@test typeof(M.left) == typeof(M.right) && typeof(M.left) == Float64
@test typeof(N.left) == typeof(N.right) && typeof(N.left) == Int
Expand Down