diff --git a/test/runtests.jl b/test/runtests.jl index d52c254..e232491 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using ParametricMCPs -using Test: @testset, @test +using Test: @testset, @test, @test_throws using Random: Random using LinearAlgebra: norm using Zygote: Zygote @@ -15,6 +15,7 @@ using FiniteDiff: FiniteDiff lower_bounds = [-Inf, -Inf, 0, 0] upper_bounds = [Inf, Inf, Inf, Inf] problem = ParametricMCPs.ParametricMCP(f, lower_bounds, upper_bounds, parameter_dimension) + problem_no_jacobian = ParametricMCPs.ParametricMCP(f, lower_bounds, upper_bounds, parameter_dimension; compute_sensitivities = false) feasible_parameters = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [rand(rng, 2) for _ in 1:10]...] infeasible_parameters = -feasible_parameters @@ -44,5 +45,14 @@ using FiniteDiff: FiniteDiff @test isapprox(∇_autodiff_reverse, ∇_finitediff; atol = 1e-4) @test isapprox(∇_autodiff_reverse, ∇_autodiff_forward; atol = 1e-4) end - end + end + + @testset "missing jacobian" begin + function dummy_pipeline(θ, problem) + solution = ParametricMCPs.solve(problem, θ) + sum(solution.z .^ 2) + end + + @test_throws ArgumentError Zygote.gradient(θ -> dummy_pipeline(θ, problem_no_jacobian), feasible_parameters[1]) + end end