From cba4f69619da18c274788327671d4a22021b1383 Mon Sep 17 00:00:00 2001 From: schillic Date: Fri, 5 Jul 2024 09:51:12 +0200 Subject: [PATCH] add option for shorter tests, used in PkgEval --- test/ForwardAlgorithms/forward.jl | 28 +++++++++++++++------------- test/runtests.jl | 26 ++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/test/ForwardAlgorithms/forward.jl b/test/ForwardAlgorithms/forward.jl index ee4b8ac..7df088a 100755 --- a/test/ForwardAlgorithms/forward.jl +++ b/test/ForwardAlgorithms/forward.jl @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 6bae9a7..354c590 100755 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,27 @@ 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 @@ -8,7 +29,8 @@ include("example_networks.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") @@ -43,4 +65,4 @@ end end end -include("Aqua.jl") +@ts include("Aqua.jl")