Skip to content

Commit

Permalink
Merge pull request #33 from JuliaReach/schillic/test_short
Browse files Browse the repository at this point in the history
Add option for shorter tests and use in PkgEval
  • Loading branch information
schillic authored Jul 5, 2024
2 parents 2b8645a + cba4f69 commit 9fb6ec2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
28 changes: 15 additions & 13 deletions test/ForwardAlgorithms/forward.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ end
@test forward(x, N, DefaultForward()) == [47.0, 94]

# exact algorithms (in this case)
for algo in (ConcreteForward(), LazyForward(), BoxForward(),
BoxForward(LazyForward()), DeepZ(), Verisig())
for algo in @tv [ConcreteForward(), LazyForward(), BoxForward(),
BoxForward(LazyForward()), DeepZ()] [Verisig()]
@test isequivalent(concretize(forward(X, N, algo)), Y)
end
# approximate algorithms
Expand Down Expand Up @@ -316,12 +316,12 @@ end
end

# algorithms not supporting ReLU activation
for algo in (DefaultForward(), Verisig())
@ts for algo in (DefaultForward(), Verisig())
@test_throws ArgumentError forward(X, N, algo)
end
end

@testset "AI² ReLU example" begin
@ts @testset "AI² ReLU example" begin
N = example_network_AI2()
W = N.layers[1].weights
b = N.layers[1].bias
Expand Down Expand Up @@ -371,7 +371,7 @@ end
end

# algorithms not supporting ReLU activation
for algo in (DefaultForward(), Verisig())
@ts for algo in (DefaultForward(), Verisig())
@test_throws ArgumentError forward(X, N, algo)
end

Expand All @@ -397,14 +397,16 @@ end
end

# Verisig result has a special type
Y = forward(X, N, Verisig())
if act == Sigmoid()
@test Y_exact overapproximate(Y, Zonotope)
elseif act == Tanh()
# this is a known case where the algorithm is unsound
@test_broken Y_exact overapproximate(Y, Zonotope)
else
error("unexpected case")
@ts begin
Y = forward(X, N, Verisig())
if act == Sigmoid()
@test Y_exact overapproximate(Y, Zonotope)
elseif act == Tanh()
# this is a known case where the algorithm is unsound
@test_broken Y_exact overapproximate(Y, Zonotope)
else
error("unexpected case")
end
end

# algorithms not supporting sigmoid activation
Expand Down
26 changes: 24 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
using Test, NeuralNetworkReachability
using ControllerFormats, LazySets

# auxiliary code to skip expensive tests
begin
__test_short = haskey(ENV, "JULIA_PKGEVAL")

macro ts(arg)
if !__test_short
quote
$(esc(arg))
end
end
end

macro tv(v1, v2)
if __test_short
return v1
else
return @eval vcat($v1, $v2)
end
end
end

include("example_networks.jl")

@testset "Optional dependencies (not loaded)" begin
include("optional_dependencies_not_loaded.jl")
end

# load optional dependencies
import IntervalConstraintProgramming, ReachabilityAnalysis, Polyhedra, CDDLib, Optim
import Polyhedra, CDDLib, Optim
@ts import IntervalConstraintProgramming, ReachabilityAnalysis

@testset "Util" begin
include("Util/Util.jl")
Expand Down Expand Up @@ -43,4 +65,4 @@ end
end
end

include("Aqua.jl")
@ts include("Aqua.jl")

0 comments on commit 9fb6ec2

Please sign in to comment.