Skip to content

Commit

Permalink
some unit test numeric type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jan 28, 2018
1 parent 2b03cc7 commit 341f611
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 35 deletions.
2 changes: 1 addition & 1 deletion test/unit_CartesianProduct.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
for N in [Float64, Float32] # TODO Rational{Int}
for N in [Float64, Float32, Rational{Int}]
# Cartesian Product of a centered 1D BallInf and a centered 2D BallInf
# Here a 3D BallInf
b1 = BallInf(N[0.], N(1.))
Expand Down
43 changes: 12 additions & 31 deletions test/unit_Polygon.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
for N in [Float64, Float32] # TODO Rational{Int}
for N in [Float64, Float32, Rational{Int}]
# Empty polygon
p = HPolygon{N}()

Expand Down Expand Up @@ -60,17 +60,17 @@ for N in [Float64, Float32] # TODO Rational{Int}
@test N[4., 2.] vp.vertices_list

# test convex hull of a set of points using the default algorithm
points = [N[0.9,0.2], N[0.4,0.6], N[0.2,0.1], N[0.1,0.3], N[0.3,0.28]]
points = to_N(N, [[0.9,0.2], [0.4,0.6], [0.2,0.1], [0.1,0.3], [0.3,0.28]])
vp = VPolygon(points) # by default, a convex hull is run
@test vertices_list(vp) == [ N[0.1,0.3],N[0.2,0.1], N[0.9,0.2],N[0.4,0.6] ]
@test vertices_list(vp) == to_N(N, [[0.1,0.3], [0.2,0.1], [0.9,0.2], [0.4,0.6] ])

vp = VPolygon(points, apply_convex_hull=false) # we can turn it off
@test vertices_list(vp) == [N[0.9,0.2], N[0.4,0.6], N[0.2,0.1], N[0.1,0.3], N[0.3,0.28]]
@test vertices_list(vp) == to_N(N, [[0.9,0.2], [0.4,0.6], [0.2,0.1], [0.1,0.3], [0.3,0.28]])

# test for pre-sorted points
points = [N[0.1, 0.3], N[0.2, 0.1], N[0.4, 0.3], N[0.4, 0.6], N[0.9, 0.2]]
points = to_N(N, [[0.1, 0.3], [0.2, 0.1], [0.4, 0.3], [0.4, 0.6], [0.9, 0.2]])
vp = VPolygon(points, algorithm="monotone_chain_sorted")
@test vertices_list(vp) == [N[0.1, 0.3], N[0.2, 0.1], N[0.9, 0.2], N[0.4, 0.6]]
@test vertices_list(vp) == to_N(N, [[0.1, 0.3], [0.2, 0.1], [0.9, 0.2], [0.4, 0.6]])

# test support vector of a VPolygon
p = HPolygon{N}()
Expand All @@ -90,19 +90,19 @@ for N in [Float64, Float32] # TODO Rational{Int}
@test σ(d, p) == N[0., 0.]

# test that #83 is fixed
v = VPolygon([N[2.0, 3.0]])
v = VPolygon(to_N(N, [[2.0, 3.0]]))
@test N[2.0, 3.0] v
@test !(N[3.0, 2.0] v)
v = VPolygon([N[2.0, 3.0], N[-1.0, -3.4]])
@test N[-1.0, -3.4] v
v = VPolygon(to_N(N, [[2.0, 3.0], [-1.0, -3.4]]))
@test to_N(N, [-1.0, -3.4]) v

# an_element function
v = VPolygon([N[2., 3.]])
v = VPolygon(to_N(N, [[2., 3.]]))
@test an_element(v) v

# subset
p1 = VPolygon([N[0., 0.],N[2., 0.]])
p2 = VPolygon([N[1., 0.]])
p1 = VPolygon(to_N(N, [[0., 0.], [2., 0.]]))
p2 = VPolygon(to_N(N, [[1., 0.]]))
@test (p2, p1) && (p2, p1, true)[1]
@test (HPolygon{N}(), p1)
@test (p1, BallInf(N[1., 0.], N(1.)))
Expand All @@ -124,22 +124,3 @@ for N in [Float64, Float32] # TODO Rational{Int}
end

end

# TODO: delete and keep the loop of above
# Test comparison of directions <= for rational entries
N = Rational{Int}
v1 = N[1.0, 0.0]
v2 = N[1.0, 1.0]
v3 = N[0.0, 1.0]
v4 = N[-1.0, 1.0]
v5 = N[-1.0, 0.0]
v6 = N[-1.0, -1.0]
v7 = N[0, -1.0]
v8 = N[1.0, -1.0]
v = [v1, v2, v3, v4, v5, v6, v7, v8]

for (i, vi) in enumerate(v)
for j in i:8
@test vi <= v[j]
end
end
2 changes: 1 addition & 1 deletion test/unit_ballinf_approximation.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import LazySets.Approximations.ballinf_approximation

for N in [Float64, Float32] # TODO Rational{Int}
for N in [Float64, Float32, Rational{Int}]
# BallInf approximation of a 3D unit ball in the 1-norm centered at [1,2,0]
b = Ball1(N[1., 2., 0.], N(1.))
bi = ballinf_approximation(b)
Expand Down
4 changes: 2 additions & 2 deletions test/unit_decompose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ for N in [Float64, Float32] # TODO Rational{Int}
d = decompose(b, Inf, Hyperrectangle)
@test d.sfarray[1] isa Hyperrectangle
d = decompose(b, to_N(N, 1e-2), Hyperrectangle)
@test d.sfarray[1] isa HPolygon # with p not Inf the set type is ignored
@test d.sfarray[1] isa HPolygon # with p not Inf the set type is ignored
d = decompose(b, to_N(N, 1e-2)) # by default uses HPolygon
@test d.sfarray[1] isa HPolygon
d = decompose(b, [to_N(N, 1e-1), to_N(N, 1e-2), to_N(N, 1e-3)])
d = decompose(b, to_N(N, [1e-1, 1e-2, 1e-3]))
@test d.sfarray[1] isa HPolygon
end

0 comments on commit 341f611

Please sign in to comment.