Skip to content

Commit 224948b

Browse files
lbenetdpsanders
authored andcommitted
Add missing set operations involving IntervalBoxes, with tests (#262)
* Add missing set operations involving `IntervalBox`es, with tests * Use metaprograming and add negative tests
1 parent 3314a37 commit 224948b

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/multidim/arithmetic.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ Base.size(X::IntervalBox{2,Float64}) = (2,)
3131
@inline broadcasted(f, x, y, Z::IntervalBox) = wrap(f.(x, y, Z.v))
3232
@inline broadcasted(f, x, Y::IntervalBox, z) = wrap(f.(x, Y.v, z))
3333

34-
for op in (:+, :-, :, :, :, :isinterior, :dot, :setdiff, :×)
34+
for op in (:+, :-, :, :, :, :, :, :isinterior, :dot, :setdiff, :×)
3535
@eval $(op)(a::SVector, b::IntervalBox) = $(op)(IntervalBox(a), b)
36-
end
37-
38-
for op in (:+, :-, :, :, :, :isinterior, :dot, :setdiff, :×)
3936
@eval $(op)(a::IntervalBox, b::SVector) = $(op)(a, IntervalBox(b))
4037
end
4138

src/multidim/intervalbox.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ big(X::IntervalBox) = big.(X)
6565
## set operations
6666

6767
# TODO: Update to use generator
68-
(X::IntervalBox{N,T}, Y::IntervalBox{N,T}) where {N,T} =
69-
all(X.v .⊆ Y.v)
68+
for (op, dotop) in ((:, :.⊆), (:, :.⊂), (:, :.⊃))
69+
@eval $(op)(X::IntervalBox{N,T}, Y::IntervalBox{N,T}) where {N,T} = all($(dotop)(X, Y))
70+
end
7071

7172
(X::IntervalBox{N,T}, Y::IntervalBox{N,T}) where {N,T} =
7273
IntervalBox(X.v .∩ Y.v)

test/multidim_tests/multidim.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,26 @@ let X, A # avoid problems with global variables
3535
@test A .^ 2 == IntervalBox(1..4, 9..16)
3636
@test B .^ 0.5 == IntervalBox(@interval(0,sqrt(2)), @interval(sqrt(3),sqrt(6)))
3737

38+
@test A A
3839
@test A B
3940
@test A.v B
41+
@test A B.v
42+
@test !(A A)
43+
@test A B
44+
@test A.v B
4045
@test A B.v
46+
@test !(B A)
47+
@test !(B A)
48+
@test B B
49+
@test B A
50+
@test B.v A
51+
@test B A.v
52+
@test !(B B)
53+
@test B A
54+
@test B.v A
55+
@test B A.v
56+
@test !(A B)
57+
@test !(A B)
4158

4259
@test A B == A
4360
@test A.v B == A

0 commit comments

Comments
 (0)