Skip to content

Commit

Permalink
Merge pull request #579 from JuliaReach/schillic/plot_tests
Browse files Browse the repository at this point in the history
#130 - Add unit tests for plotting
  • Loading branch information
schillic authored Aug 23, 2018
2 parents e2cdafe + 438c9c8 commit 67426ec
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ include("to_N.jl")
global test_suite_basic = true
global test_suite_doctests = VERSION >= v"0.7-" # only run doctests with new Julia version
global test_suite_polyhedra = false
global test_suite_plotting = false

if (length(ARGS) == 0) || (ARGS[1] == "--default")
# default test suite including doctests
Expand All @@ -20,9 +21,13 @@ elseif ARGS[1] == "--basic"
elseif ARGS[1] == "--polyhedra"
# Polyhedra.jl test suite
test_suite_polyhedra = true
elseif ARGS[1] == "--plot"
# plotting test suite
test_suite_plotting = true
elseif ARGS[1] == "--all"
# complete test suite
test_suite_polyhedra = true
test_suite_plotting = true
else
error("unknown parameter 1: $(ARGS[1])")
end
Expand Down Expand Up @@ -95,6 +100,10 @@ if test_suite_basic
@time @testset "LazySets.interfaces" begin include("unit_interfaces.jl") end
end

if test_suite_plotting
@time @testset "LazySets.plotting" begin include("unit_plot.jl") end
end

if test_suite_doctests
if isdefined(@__MODULE__, :Polyhedra)
println("skipping doctests due to a clash with Polyhedra")
Expand Down
171 changes: 171 additions & 0 deletions test/unit_plot.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
using Plots

for N in [Float64, Rational{Int}, Float32]
p0 = zero(N)
p1 = one(N)
v0 = zeros(N, 2)
v1 = ones(N, 2)

# ---------------
# set definitions
# ---------------

# bounded basic set types
b1 = Ball1(v0, p1)
bi = BallInf(v0, p1)
hr = Hyperrectangle(v0, v1)
itv = Interval(p0, p1)
ls = LineSegment(v0, v1)
st = Singleton(v1)
zt = Zonotope(v0, Diagonal(N[1, 1]))
zs = ZeroSet{N}(2)

# polygon/polytope types
constraints = [LinearConstraint([p1, p0], p1),
LinearConstraint([p0, p1], p1),
LinearConstraint([-p1, p0], p0),
LinearConstraint([p0, -p1], p0)]
hpg = HPolygon(constraints)
hpgo = HPolygonOpt(constraints)
hpt = HPolytope(constraints)
vertices = vertices_list(bi)
vpg = VPolygon(vertices)
vpt = VPolytope(vertices)

# empty set
es = EmptySet{N}()

# infinite sets
hs = HalfSpace(v1, p1)
hp = Hyperplane(v1, p1)
l = Line(v1, p1)

# unary set operations
sih = SymmetricIntervalHull(b1)
lm = LinearMap(N[2. 1.; 1. 2.], bi)

# binary set operations
ch = ConvexHull(b1, bi)
cha = ConvexHullArray([b1, bi])
its = Intersection(b1, bi)
itsa = IntersectionArray([b1, bi])
ms = MinkowskiSum(b1, bi)
msa = MinkowskiSumArray([b1, bi])
cms = CacheMinkowskiSum([b1, bi])
cp = CartesianProduct(itv, itv)
cpa = CartesianProductArray([itv, itv])

# -----
# plots
# -----

# direct
plot(b1)
plot(bi)
plot(hr)
plot(itv)
plot(ls)
plot(st)
plot(zt)
plot(zs)
plot(hpg)
plot(hpgo)
plot(hpt)
plot(vpg)
@test_throws AssertionError plot(vpt) # TODO see #574
@test_throws ErrorException plot(es) # TODO see #577
@test_throws ErrorException plot(hs) # TODO see #576
@test_throws ErrorException plot(hp) # TODO see #576
@test_throws ErrorException plot(l) # TODO see #576
plot(ch)
plot(cha)
@test_throws ErrorException plot(its) # TODO not implemented yet
@test_throws ErrorException plot(itsa) # TODO not implemented yet
plot(sih)
plot(lm)
plot(ms)
plot(msa)
plot(cms)
plot(cp)
plot(cpa)

# ε-close
ε = N(1e-2)
if N == Float64 # TODO see #578
plot(b1, ε)
plot(bi, ε)
plot(hr, ε)
plot(ls, ε)
@test_throws AssertionError plot(itv, ε) # TODO see #575
plot(st, ε)
plot(zt, ε)
plot(zs, ε)
plot(hpg, ε)
plot(hpgo, ε)
plot(hpt, ε)
plot(vpg, ε)
@test_throws AssertionError plot(vpt, ε) # TODO see #574
@test_throws AssertionError plot(es, ε) # TODO see #577
@test_throws ErrorException plot(hs, ε) # TODO see #576/#578
@test_throws ErrorException plot(hp, ε) # TODO see #576/#578
@test_throws ErrorException plot(l, ε) # TODO see #576/#578
@test_throws ErrorException plot(its, ε) # TODO not implemented yet
@test_throws ErrorException plot(itsa, ε) # TODO not implemented yet
plot(ch, ε)
plot(cha, ε)
plot(sih, ε)
plot(lm, ε)
plot(ms, ε)
plot(msa, ε)
plot(cms, ε)
plot(cp, ε)
plot(cpa, ε)
else
@test_throws ErrorException plot(b1, ε) # TODO see #578
end
end

# set types that do not work with Rational{Int}
for N in [Float64, Float32]
v0 = zeros(N, 2)
p1 = one(N)

# ---------------
# set definitions
# ---------------

# bounded basic set types
b2 = Ball2(v0, p1)
bp = Ballp(N(1.5), v0, p1)
el = Ellipsoid(v0, Diagonal(N[1, 1]))

# unary set operations
spI = SparseMatrixCSC{N}(2I, 2, 2)
sme = SparseMatrixExp(spI)
em = ExponentialMap(sme, b2)
psme = ProjectionSparseMatrixExp(spI, sme, spI)
epm = ExponentialProjectionMap(psme, b2)

# -----
# plots
# -----

# direct
plot(b2)
plot(bp)
plot(el)
plot(em)
plot(epm)

# ε-close
ε = N(1e-2)
if N == Float64 # TODO see #578
plot(b2, ε)
plot(bp, ε)
plot(el, ε)
plot(em, ε)
plot(epm, ε)
else
@test_throws ErrorException plot(b2, ε) # TODO see #578
end
end

0 comments on commit 67426ec

Please sign in to comment.