Skip to content

Commit

Permalink
unit tests for decompose
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Mar 3, 2018
1 parent 9f2f158 commit b6a0495
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions test/unit_decompose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ for N in [Float64, Float32] # TODO Rational{Int}
# ======================================
# Run decompose for different set types
# ======================================
function test_directions(set)
res = σ(N[1, 0], set)[1] == one(N)
res &= σ(N[0, 1], set)[2] == one(N)
res &= σ(N[-1, 0], set)[1] == -one(N)
res &= σ(N[0, -1], set)[2] == -one(N)
return res
end
b = BallInf(zeros(N, 6), one(N))
d = decompose(b, set_type=HPolygon)
@test d.array[1] isa HPolygon
@test d.array[1] isa HPolygon && test_directions(d.array[1])
d = decompose(b, set_type=Hyperrectangle)
@test d.array[1] isa Hyperrectangle
@test d.array[1] isa Hyperrectangle && test_directions(d.array[1])
d = decompose(b, set_type=HPolygon, ɛ=to_N(N, 1e-2))
@test d.array[1] isa HPolygon
@test d.array[1] isa HPolygon && test_directions(d.array[1])

# ===================
# 1D/3D decomposition
Expand All @@ -41,4 +48,14 @@ for N in [Float64, Float32] # TODO Rational{Int}
@test length(d.array) == 7
d = decompose(b, set_type=Hyperrectangle, blocks=[1,2,3,1])
@test length(d.array) == 4

# =======================
# default block structure
# =======================
# even dimension
b = BallInf(zeros(N, 6), one(N))
d = decompose(b)
# odd dimension
b = BallInf(zeros(N, 7), one(N))
d = decompose(b)
end

0 comments on commit b6a0495

Please sign in to comment.