Skip to content

Commit 80875fe

Browse files
committed
fix decorated interval construction with invalid input
1 parent 69cd825 commit 80875fe

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/decorations/intervals.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ DecoratedInterval(I::Interval{T}, d::DECORATION) where T<:AbstractFloat =
4747
DecoratedInterval{T}(I, d)
4848

4949
function DecoratedInterval(a::T, b::T, d::DECORATION) where T<:Real
50-
a > b && return nai(T)
50+
is_valid_interval(a, b) || return nai(T)
5151
DecoratedInterval(Interval(a,b), d)
5252
end
5353

@@ -63,7 +63,7 @@ DecoratedInterval(a::T, b::S, d::DECORATION) where {T<:Real, S<:Real} =
6363
DecoratedInterval(I::Interval) = DecoratedInterval(I, decoration(I))
6464

6565
function DecoratedInterval(a::T, b::T) where T<:Real
66-
a > b && return nai(T)
66+
is_valid_interval(a, b) || return nai(T)
6767
DecoratedInterval(Interval(a,b))
6868
end
6969

test/decoration_tests/decoration_tests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ let b
5454
b = @decorated 3 4
5555

5656
@test dist(a, b) == 2.0
57+
58+
# invalid input
59+
@test isnai(@decorated(3, 1, com))
60+
@test isnai(@decorated(3, 1))
61+
@test isnai(@decorated(Inf, Inf))
62+
@test isnai(@decorated(-Inf, -Inf))
63+
@test isnai(@decorated(NaN, 3))
64+
@test isnai(@decorated(3, NaN))
65+
@test isnai(@decorated(NaN, NaN))
5766
end
5867

5968
@testset "Convert string to DecoratedInterval" begin

0 commit comments

Comments
 (0)