|
12 | 12 | @testset "Operations on boxes" begin
|
13 | 13 | A = IntervalBox(1..2, 3..4)
|
14 | 14 | B = IntervalBox(0..2, 3..6)
|
| 15 | + s = @SVector [1, 2] |
15 | 16 |
|
16 | 17 | @test 2*A == A*2 == IntervalBox(2..4, 6..8)
|
17 | 18 | @test typeof(2*A) == IntervalBox{2, Float64}
|
18 | 19 | @test A + B == IntervalBox(1..4, 6..10)
|
| 20 | + @test A + B.v == IntervalBox(1..4, 6..10) |
| 21 | + @test A.v + B == IntervalBox(1..4, 6..10) |
| 22 | + @test A + s == IntervalBox(2..3, 5..6) |
| 23 | + @test A - B == IntervalBox(-1..2, -3..1) |
| 24 | + @test A.v - B == IntervalBox(-1..2, -3..1) |
| 25 | + @test A - B.v == IntervalBox(-1..2, -3..1) |
| 26 | + @test A - s == IntervalBox(0..1, 1..2) |
19 | 27 | @test 2 + A == IntervalBox(3..4,5..6)
|
20 | 28 | @test A + 2 == IntervalBox(3..4,5..6)
|
21 | 29 | @test -A == IntervalBox((-2)..(-1), (-4)..(-3))
|
22 | 30 | @test 2 - A == IntervalBox(0..1, (-2)..(-1))
|
23 | 31 | @test B - 2 == IntervalBox((-2)..0, 1..4)
|
24 | 32 | @test dot(A, B) == @interval(9, 28)
|
| 33 | + @test dot(A, B.v) == @interval(9, 28) |
| 34 | + @test dot(A.v, B) == @interval(9, 28) |
25 | 35 | @test A .* B == IntervalBox(0..4, 9..24)
|
26 | 36 | @test A ./ A == IntervalBox((0.5)..2, (0.75)..(4/3))
|
27 | 37 | @test 1 ./ B == IntervalBox((0.5)..Inf, (1/6)..(1/3))
|
|
30 | 40 | @test B .^ 0.5 == IntervalBox(@interval(0,sqrt(2)), @interval(sqrt(3),sqrt(6)))
|
31 | 41 |
|
32 | 42 | @test A ⊆ B
|
| 43 | + @test A.v ⊆ B |
| 44 | + @test A ⊆ B.v |
| 45 | + |
33 | 46 | @test A ∩ B == A
|
| 47 | + @test A.v ∩ B == A |
| 48 | + @test A ∩ B.v == A |
| 49 | + |
34 | 50 | @test A ∪ B == B
|
| 51 | + @test A.v ∪ B == B |
| 52 | + @test A ∪ B.v == B |
35 | 53 |
|
36 | 54 | X = IntervalBox(1..2, 3..4)
|
37 | 55 | Y = IntervalBox(3..4, 3..4)
|
|
88 | 106 | @test setdiff(X, Y) == [ IntervalBox(3..4, 3..4),
|
89 | 107 | IntervalBox(2..3, 3..5) ]
|
90 | 108 |
|
| 109 | + @test setdiff(X.v, Y) == [ IntervalBox(3..4, 3..4), |
| 110 | + IntervalBox(2..3, 3..5) ] |
| 111 | + |
| 112 | + @test setdiff(X, Y.v) == [ IntervalBox(3..4, 3..4), |
| 113 | + IntervalBox(2..3, 3..5) ] |
91 | 114 |
|
92 | 115 | X = IntervalBox(2..5, 3..6)
|
93 | 116 | Y = IntervalBox(-10..10, 4..5)
|
|
146 | 169 | @test Y == IntervalBox(Interval(0, 2), Interval(3, 5), Interval(4, 8))
|
147 | 170 | @test diam(Y) == 4
|
148 | 171 |
|
| 172 | + Z = X × Y |
| 173 | + @test isa(Z, IntervalBox) |
| 174 | + @test length(Z) == 5 |
| 175 | + @test Z == IntervalBox(Interval(0, 2), Interval(3, 5), Interval(0, 2), Interval(3, 5), Interval(4, 8)) |
| 176 | + @test diam(Z) == 4 |
| 177 | + |
| 178 | + Z = X × Y.v |
| 179 | + @test isa(Z, IntervalBox) |
| 180 | + @test length(Z) == 5 |
| 181 | + @test Z == IntervalBox(Interval(0, 2), Interval(3, 5), Interval(0, 2), Interval(3, 5), Interval(4, 8)) |
| 182 | + @test diam(Z) == 4 |
| 183 | + |
| 184 | + Z = X.v × Y |
| 185 | + @test isa(Z, IntervalBox) |
| 186 | + @test length(Z) == 5 |
| 187 | + @test Z == IntervalBox(Interval(0, 2), Interval(3, 5), Interval(0, 2), Interval(3, 5), Interval(4, 8)) |
| 188 | + @test diam(Z) == 4 |
| 189 | + |
149 | 190 | @test mid(IntervalBox(0..1, 3), 0.75) == [0.75, 0.75, 0.75]
|
150 | 191 | end
|
151 | 192 |
|
|
155 | 196 | @test IntervalBox(1..2, Val{5}) == (1..2) × (1..2) × (1..2) × (1..2) × (1..2)
|
156 | 197 |
|
157 | 198 | @test IntervalBox(1..2, 3) == IntervalBox(1..2, Val{3})
|
| 199 | + @test IntervalBox((1..2, 2..3)) == IntervalBox(1..2, 2..3) |
| 200 | + @test IntervalBox((1, 2)) == IntervalBox(1..1, 2..2) |
| 201 | + @test IntervalBox( (1, 2, 3) ) == IntervalBox(1..1, 2..2, 3..3) |
| 202 | + @test IntervalBox( (1, 2, 3.1) ) == IntervalBox(1..1, 2..2, interval(3.1)) |
| 203 | + @test IntervalBox( SVector(1, 2, 3.1) ) == IntervalBox(1..1, 2..2, interval(3.1)) |
| 204 | + @test IntervalBox( interval.(SVector(1, 2, 3.1)) ) == IntervalBox(1..1, 2..2, interval(3.1)) |
| 205 | + @test IntervalBox(3) == IntervalBox(3..3) |
| 206 | + @test IntervalBox(1:5) == IntervalBox(1..1, 2..2, 3..3, 4..4, 5..5) |
| 207 | + @test IntervalBox([1:5...]) == IntervalBox(1..1, 2..2, 3..3, 4..4, 5..5) |
| 208 | + @test IntervalBox((1..2) × (2..3), 2) == IntervalBox((1..2) × (2..3) × (1..2) × (2..3)) |
158 | 209 |
|
159 | 210 | end
|
160 | 211 |
|
|
0 commit comments