Skip to content

Commit 02b0f6b

Browse files
authored
Allow == if one of the operand is a thin interval (#631)
* Allow `==` if one of the operand is a thin interval * Update test suite
1 parent 5275e5c commit 02b0f6b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/intervals/real_interface.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ Base.hash(x::Interval, h::UInt) = hash(sup(x), hash(inf(x), hash(Interval, h)))
8080

8181
for T (:BareInterval, :Interval)
8282
@eval begin
83-
Base.:(==)(::$T, ::$T) = # also returned when calling `≤`, `≥`, `isequal`
84-
throw(ArgumentError("`==` is purposely not supported for intervals. See instead `isequal_interval`"))
83+
function Base.:(==)(x::$T, y::$T) # also returned when calling `≤`, `≥`, `isequal`
84+
isthin(x) && return sup(x) == y
85+
isthin(y) && return x == sup(y)
86+
return throw(ArgumentError("`==` is purposely not supported for intervals. See instead `isequal_interval`"))
87+
end
8588

8689
Base.:<(::$T, ::$T) = # also returned when calling `isless`, `>`
8790
throw(ArgumentError("`<` is purposely not supported for intervals. See instead `isstrictless`, `strictprecedes`"))

test/interval_tests/consistency.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@
340340

341341
@testset "Disallowed `Real` functionalities" begin
342342
x, y = interval(1), interval(2)
343-
@test_throws ArgumentError x == y
343+
@test x != y
344+
@test (interval(1, 2) != y) & (y != interval(1, 2))
345+
@test_throws ArgumentError interval(1, 2) == interval(1, 2)
344346
@test_throws ArgumentError x < y
345347
@test_throws ArgumentError isdisjoint(x, y)
346348
@test_throws ArgumentError issubset(x, y)

0 commit comments

Comments
 (0)