diff --git a/test/unit_HalfSpace.jl b/test/unit_HalfSpace.jl index b7964930b9..c950d2ef6e 100644 --- a/test/unit_HalfSpace.jl +++ b/test/unit_HalfSpace.jl @@ -138,35 +138,34 @@ for N in [Float64] o = N[0.07768723948819561, -0.5762273280928935, 0.28897399484750297, 1.9299362784322858] H = HalfSpace(N[-0.09291863543681655, -0.2176689899601838, -0.07453829739226348, 0.048948632014371496], N(0.1911363393469332)) @test o ∈ H -end - -# tests that require ModelingToolkit -@static if VERSION >= v"1.3" && isdefined(@__MODULE__, :ModelingToolkit) - vars = @variables x y - @test HalfSpace(2x + 3y < 5) == HalfSpace([2.0, 3.0], 5.0) - @test HalfSpace(2x + 3y < 5, vars) == HalfSpace([2.0, 3.0], 5.0) - @test HalfSpace(2x + 3y < 5, N=Int) == HalfSpace([2, 3], 5) + # tests that require ModelingToolkit + @static if VERSION >= v"1.3" && isdefined(@__MODULE__, :ModelingToolkit) + vars = @variables x y + @test HalfSpace(2x + 3y < 5) == HalfSpace([2.0, 3.0], 5.0) + @test HalfSpace(2x + 3y < 5, vars) == HalfSpace([2.0, 3.0], 5.0) + @test HalfSpace(2x + 3y < 5, N=Int) == HalfSpace([2, 3], 5) - @test HalfSpace(2x + 3y > 5) == HalfSpace([-2.0, -3.0], -5.0) - @test HalfSpace(2x + 3y > 5, vars) == HalfSpace([-2.0, -3.0], -5.0) + @test HalfSpace(2x + 3y > 5) == HalfSpace([-2.0, -3.0], -5.0) + @test HalfSpace(2x + 3y > 5, vars) == HalfSpace([-2.0, -3.0], -5.0) - @test HalfSpace(2x + 3y ≤ 5) == HalfSpace([2.0, 3.0], 5.0) - @test HalfSpace(2x + 3y ≤ 5, vars) == HalfSpace([2.0, 3.0], 5.0) + @test HalfSpace(2x + 3y ≤ 5) == HalfSpace([2.0, 3.0], 5.0) + @test HalfSpace(2x + 3y ≤ 5, vars) == HalfSpace([2.0, 3.0], 5.0) - @test HalfSpace(2x <= 5y - 1) == HalfSpace([2.0, -5.0], -1.0) - @test HalfSpace(2x ≤ 5y - 1) == HalfSpace([2.0, -5.0], -1.0) + @test HalfSpace(2x <= 5y - 1) == HalfSpace([2.0, -5.0], -1.0) + @test HalfSpace(2x ≤ 5y - 1) == HalfSpace([2.0, -5.0], -1.0) - @test HalfSpace(2x + 3y ≥ 5) == HalfSpace([-2.0, -3.0], -5.0) - @test HalfSpace(2x + 3y ≥ 5, vars) == HalfSpace([-2.0, -3.0], -5.0) + @test HalfSpace(2x + 3y ≥ 5) == HalfSpace([-2.0, -3.0], -5.0) + @test HalfSpace(2x + 3y ≥ 5, vars) == HalfSpace([-2.0, -3.0], -5.0) - # doesn't work because get_vars returns variables [y, x] - # => both tests below require vars to pass - @test HalfSpace(2x ≥ 5y - 1, vars) == HalfSpace([-2.0, 5.0], 1.0) - @test HalfSpace(2x >= 5y - 1, vars) == HalfSpace([-2.0, 5.0], 1.0) + # doesn't work because get_vars returns variables [y, x] + # => both tests below require vars to pass + @test HalfSpace(2x ≥ 5y - 1, vars) == HalfSpace([-2.0, 5.0], 1.0) + @test HalfSpace(2x >= 5y - 1, vars) == HalfSpace([-2.0, 5.0], 1.0) - # test with sparse variables - @variables x[1:5] - @test HalfSpace(2x[1] + 5x[4] <= 10., x) == HalfSpace([2.0, 0.0, 0.0, 5.0, 0.0], 10.0) - @test HalfSpace(2x[1] + 5x[4] >= -10. + x[3], x) == HalfSpace([-2.0, 0.0, 1.0, -5.0, 0.0], 10.0) + # test with sparse variables + @variables x[1:5] + @test HalfSpace(2x[1] + 5x[4] <= 10., x) == HalfSpace([2.0, 0.0, 0.0, 5.0, 0.0], 10.0) + @test HalfSpace(2x[1] + 5x[4] >= -10. + x[3], x) == HalfSpace([-2.0, 0.0, 1.0, -5.0, 0.0], 10.0) + end end diff --git a/test/unit_Hyperplane.jl b/test/unit_Hyperplane.jl index e1b9cab6d6..a9a2e6668d 100644 --- a/test/unit_Hyperplane.jl +++ b/test/unit_Hyperplane.jl @@ -114,22 +114,22 @@ for N in [Float64] b = BallInf(N[2, 2, 2], N(1)) empty_intersection, v = is_intersection_empty(b, hp, true) @test !empty_intersection && !is_intersection_empty(b, hp) && v ∈ hp && v ∈ b -end -# tests that require ModelingToolkit -@static if VERSION >= v"1.3" && isdefined(@__MODULE__, :ModelingToolkit) - vars = @variables x y - @test Hyperplane(2x + 3y == 5) == Hyperplane([2.0, 3.0], 5.0) - @test Hyperplane(2x + 3y == 5, N=Int) == Hyperplane([2, 3], 5) - @test Hyperplane(2x + 3y == 5, vars) == Hyperplane([2.0, 3.0,], 5.0) - @test Hyperplane(2x == 5y) == Hyperplane([2.0, -5.0,], 0.0) - @test Hyperplane(2x == 5y, vars) == Hyperplane([2.0, -5.0,], 0.0) - - # test with sparse variables - @variables x[1:5] - @test Hyperplane(2x[1] + 5x[4] == 10., x) == Hyperplane([2.0, 0.0, 0.0, 5.0, 0.0], 10.0) - - # test passing a combination of operations - vars = @variables x[1:2] t - @test Hyperplane(x[1] == t, vars) == Hyperplane([1.0, 0.0, -1.0], 0.0) + # tests that require ModelingToolkit + @static if VERSION >= v"1.3" && isdefined(@__MODULE__, :ModelingToolkit) + vars = @variables x y + @test Hyperplane(2x + 3y == 5) == Hyperplane([2.0, 3.0], 5.0) + @test Hyperplane(2x + 3y == 5, N=Int) == Hyperplane([2, 3], 5) + @test Hyperplane(2x + 3y == 5, vars) == Hyperplane([2.0, 3.0,], 5.0) + @test Hyperplane(2x == 5y) == Hyperplane([2.0, -5.0,], 0.0) + @test Hyperplane(2x == 5y, vars) == Hyperplane([2.0, -5.0,], 0.0) + + # test with sparse variables + @variables x[1:5] + @test Hyperplane(2x[1] + 5x[4] == 10., x) == Hyperplane([2.0, 0.0, 0.0, 5.0, 0.0], 10.0) + + # test passing a combination of operations + vars = @variables x[1:2] t + @test Hyperplane(x[1] == t, vars) == Hyperplane([1.0, 0.0, -1.0], 0.0) + end end diff --git a/test/unit_Intersection.jl b/test/unit_Intersection.jl index 975ea3c6d5..d2ea185665 100644 --- a/test/unit_Intersection.jl +++ b/test/unit_Intersection.jl @@ -41,26 +41,26 @@ for N in [Float64, Rational{Int}, Float32] @test LazySets.is_array_constructor(IntersectionArray) # intersection of an array of sets - IA = IntersectionArray([B, H]) + IArr = IntersectionArray([B, H]) # dim - @test dim(IA) == 2 + @test dim(IArr) == 2 # support vector (currently throws an error) - @test_throws ErrorException σ(ones(N, 2), IA) + @test_throws ErrorException σ(ones(N, 2), IArr) # boundedness - @test isbounded(IA) + @test isbounded(IArr) @test isbounded(IntersectionArray([Singleton(N[1]), HalfSpace(N[1], N(1))])) # the following tests crash because ρ(::IntersectionArray) is not implemented yet @test_throws ErrorException isbounded(IntersectionArray([HalfSpace(N[1], N(1)), HalfSpace(N[1], N(-1))])) @test_throws ErrorException !isbounded(IntersectionArray([HalfSpace(ones(N, 2), N(1)), HalfSpace(ones(N, 2), N(-1))])) # isempty - @test_throws MethodError isempty(IA) + @test_throws MethodError isempty(IArr) # membership - @test ones(N, 2) ∈ IA && N[5, 5] ∉ IA + @test ones(N, 2) ∈ IArr && N[5, 5] ∉ IArr # array getter v = Vector{LazySet{N}}() @@ -70,7 +70,7 @@ for N in [Float64, Rational{Int}, Float32] IntersectionArray(10, N) # concretize - @test concretize(IA) == intersection(B, H) + @test concretize(IArr) == intersection(B, H) # ================ # common functions @@ -78,7 +78,7 @@ for N in [Float64, Rational{Int}, Float32] # absorbing element @test absorbing(Intersection) == absorbing(IntersectionArray) == EmptySet - @test I ∩ E == E ∩ I == IA ∩ E == E ∩ IA == E ∩ E == E + @test I ∩ E == E ∩ I == IArr ∩ E == E ∩ IArr == E ∩ E == E end # ====================== @@ -89,9 +89,9 @@ for N in [Float64] B = BallInf(ones(N, 2), N(3)) H = Hyperrectangle(ones(N, 2), ones(N, 2)) I = B ∩ H - IA = IntersectionArray([B, H]) + IArr = IntersectionArray([B, H]) clist1 = constraints_list(I) - clist2 = constraints_list(IA) + clist2 = constraints_list(IArr) @test ispermutation(clist1, clist2) && ispermutation(clist1, [HalfSpace(N[1, 0], N(2)), HalfSpace(N[0, 1], N(2)), diff --git a/test/unit_Polyhedron.jl b/test/unit_Polyhedron.jl index b7932cf571..4615bc4bcc 100644 --- a/test/unit_Polyhedron.jl +++ b/test/unit_Polyhedron.jl @@ -115,8 +115,7 @@ for N in [Float64, Rational{Int}, Float32] end # default Float64 constructors -unconstrained_HPolyhedron = HPolyhedron() -@test unconstrained_HPolyhedron isa HPolyhedron{Float64} +@test HPolyhedron() isa HPolyhedron{Float64} # tests that only work with Float64 and Float32 for N in [Float64, Float32] @@ -356,12 +355,12 @@ for N in [Float64] @test πP isa HPolyhedron{N} @test ispermutation(constraints_list(πP), [HalfSpace(N[-1, 0], N(0)), HalfSpace(N[0, -1], N(0))]) end -end -# tests that require ModelingToolkit -@static if VERSION >= v"1.3" && isdefined(@__MODULE__, :ModelingToolkit) - vars = @variables x y - p1 = HPolyhedron([x + y <= 1, x + y >= -1, x - y <= 1, x - y >= -1], vars) - b1 = Ball1(zeros(2), 1.0) - @test isequivalent(p1, b1) + # tests that require ModelingToolkit + @static if VERSION >= v"1.3" && isdefined(@__MODULE__, :ModelingToolkit) + vars = @variables x y + p1 = HPolyhedron([x + y <= 1, x + y >= -1, x - y <= 1, x - y >= -1], vars) + b1 = Ball1(zeros(2), 1.0) + @test isequivalent(p1, b1) + end end diff --git a/test/unit_comparisons.jl b/test/unit_comparisons.jl index c10ce54e80..4e0a657885 100644 --- a/test/unit_comparisons.jl +++ b/test/unit_comparisons.jl @@ -1,6 +1,6 @@ using LazySets: _leq, _geq, isapproxzero, _isapprox, _ztol -# approximate <= and +# approximate <= @test _leq(2e-15, 1e-15) && _leq(1e-15, 2e-15) @test _leq(1//100, 1//99) && _leq(1//100, 0.099) diff --git a/test/unit_samples.jl b/test/unit_samples.jl index 319355ccef..b16a59d8db 100644 --- a/test/unit_samples.jl +++ b/test/unit_samples.jl @@ -1,19 +1,21 @@ using Distributions: Uniform -P1 = BallInf([0.6, 0.1, -1.3, -0.4, 0.2], 0.6) -A = [1.0 0.0; - 0.0 1.0; - -1.0 0.0; - 0.0 -1.0] -b = [1.0, 2.0, 3.0, 4.0] -P2 = HPolyhedron(A, b) -P3 = HPolyhedron([0.0 0.1], [3.0]) -P4 = Ball2([0.2, -0.3, -1.1, 0.6, -0.7], 0.4) +for N in [Float64] + P1 = BallInf([0.6, 0.1, -1.3, -0.4, 0.2], 0.6) + A = [1.0 0.0; + 0.0 1.0; + -1.0 0.0; + 0.0 -1.0] + b = [1.0, 2.0, 3.0, 4.0] + P2 = HPolyhedron(A, b) + P3 = HPolyhedron([0.0 0.1], [3.0]) + P4 = Ball2([0.2, -0.3, -1.1, 0.6, -0.7], 0.4) -## Test rand samples are contained in the set -p1 = LazySets.sample(P1) -@test p1 ∈ P1 -p1_samples = LazySets.sample(P1, 100) -@test sum(p1_samples .∈ Ref(P1)) == length(p1_samples) + ## Test rand samples are contained in the set + p1 = LazySets.sample(P1) + @test p1 ∈ P1 + p1_samples = LazySets.sample(P1, 100) + @test sum(p1_samples .∈ Ref(P1)) == length(p1_samples) -@test LazySets.RejectionSampler(P2).box_approx == [Uniform(-3.0,1.0), Uniform(-4.0,2.0)] + @test LazySets.RejectionSampler(P2).box_approx == [Uniform(-3.0,1.0), Uniform(-4.0,2.0)] +end diff --git a/test/unit_util.jl b/test/unit_util.jl index b58ade6ae8..ac4284d5d8 100644 --- a/test/unit_util.jl +++ b/test/unit_util.jl @@ -48,7 +48,7 @@ for _dummy_ in 1:1 # avoid global variable warnings # removal of zero columns A = N[1 2; 3 4] @test remove_zero_columns(A) === A - @test remove_zero_columns(sparse(A)) == A + @test remove_zero_columns(sparse(A)) == A B = N[1 0 2; 3 0 4] @test remove_zero_columns(B) == remove_zero_columns(sparse(B)) == A