diff --git a/src/intervals/interval_operations/boolean.jl b/src/intervals/interval_operations/boolean.jl index 73d196cba..dcbfa5328 100644 --- a/src/intervals/interval_operations/boolean.jl +++ b/src/intervals/interval_operations/boolean.jl @@ -28,8 +28,6 @@ function isequalinterval(a::Interval, b::Interval) isemptyinterval(a) && isemptyinterval(b) && return true return inf(a) == inf(b) && sup(a) == sup(b) end -Base.:(==)(::Interval, ::Interval) = - throw(ArgumentError("`==` is purposely not supported, use `isequalinterval` instead")) """ isequalinterval(a::Interval, x::Real) @@ -165,7 +163,8 @@ function ismember(x::Real, a::Interval) return inf(a) ≤ x ≤ sup(a) end -ismember(::Interval, ::Interval) = throw(ArgumentError("ismember(::Interval, ::Interval) is not defined, maybe you meant isweaklysubset")) +ismember(::Interval, ::Interval) = + throw(ArgumentError("`ismember` is purposely not supported for two interval arguments. See instead `isweaklysubset`.")) ismember(x::Real, a::Complex{<:Interval}) = ismember(x, real(a)) && ismember(0, imag(a)) ismember(x::Complex, a::Complex{<:Interval}) = ismember(real(x), real(a)) && ismember(imag(x), imag(a)) diff --git a/src/intervals/real_interface.jl b/src/intervals/real_interface.jl index aee4352b1..802ba197b 100644 --- a/src/intervals/real_interface.jl +++ b/src/intervals/real_interface.jl @@ -58,3 +58,32 @@ hash(x::Interval, h::UInt) = hash(sup(x), hash(inf(x), hash(Interval, h))) # TODO No idea where this comes from and if it is the correct place to put it. dist(a::Interval, b::Interval) = max(abs(inf(a)-inf(b)), abs(sup(a)-sup(b))) + +# + +Base.:(==)(::Interval, ::Interval) = # also returned when calling `≤`, `≥`, `isequal` + throw(ArgumentError("`==` is purposely not supported for intervals. See instead `isequalinterval`.")) + +Base.:<(::Interval, ::Interval) = # also returned when calling `>` + throw(ArgumentError("`<` is purposely not supported for intervals. See instead `isweaklyless`, `precedes`.")) + +Base.isdisjoint(::Interval, ::Interval) = + throw(ArgumentError("`isdisjoint` is purposely not supported for intervals. See instead `isdisjointinterval`.")) + +Base.issubset(::Interval, ::Interval) = + throw(ArgumentError("`issubset` is purposely not supported for intervals. See instead `isweaklysubset`.")) + +Base.in(::Interval, ::Interval) = + throw(ArgumentError("`in` is purposely not supported for intervals. See instead `ismember`.")) + +Base.isempty(::Interval) = + throw(ArgumentError("`isempty` is purposely not supported for intervals. See instead `isemptyinterval`.")) + +Base.isfinite(::Interval) = # also returned when calling `isinf` + throw(ArgumentError("`isfinite` is purposely not supported for intervals. See instead `isbounded`.")) + +Base.isnan(::Interval) = + throw(ArgumentError("`isnan` is purposely not supported for intervals. See instead `isnai`.")) + +Base.isinteger(::Interval) = + throw(ArgumentError("`isinteger` is purposely not supported for intervals. See instead `isthininteger`.")) diff --git a/test/interval_tests/consistency.jl b/test/interval_tests/consistency.jl index 129b57888..041016d94 100644 --- a/test/interval_tests/consistency.jl +++ b/test/interval_tests/consistency.jl @@ -364,4 +364,17 @@ import IntervalArithmetic: unsafe_interval end end + @testset "Disallowed `Real` functionalities" begin + x, y = interval(1), interval(2) + @test_throws ArgumentError x == y + @test_throws ArgumentError x < y + @test_throws ArgumentError isdisjoint(x, y) + @test_throws ArgumentError issubset(x, y) + @test_throws ArgumentError x in y + @test_throws ArgumentError isempty(x) + @test_throws ArgumentError isfinite(x) + @test_throws ArgumentError isnan(x) + @test_throws ArgumentError isinteger(x) + end + end