Skip to content

Commit

Permalink
Check bounds type at construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolaru committed Feb 9, 2025
1 parent 51db09e commit af32069
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/piecewise.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
struct Domain{L, R, T, S}
lo::T
hi::S

function Domain{L, R, T, S}(lo::T, hi::S) where {L, R, T, S}
(!(L in (:open, :closed)) || !(R in (:open, :closed))) && throw(ErrorException(
"Domain bound must be either :open or :closed, got $L and $R instead"
))
return new{L, R, T, S}(lo, hi)
end
end

Domain{L, R}(lo::T, hi::S) where {T, S, L, R} = Domain{L, R, T, S}(lo, hi)
Expand Down
5 changes: 5 additions & 0 deletions test/interval_tests/piecewise.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
using IntervalArithmetic: leftof

@testset "Domain" begin
@testset "Construction" begin
@test_throws ErrorException Domain{:oopen, :closed}(0, 1)
@test_throws ErrorException Domain{:open, :close}(0, 1)
end

@testset "leftof" begin
d1 = Domain{:open, :closed}(0, 1)
d2 = Domain{:open, :open}(0, 1)
Expand Down

0 comments on commit af32069

Please sign in to comment.