Skip to content

Commit

Permalink
added @test_throws
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Palafox committed Oct 13, 2023
1 parent b59676d commit 2fd05da
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 2fd05da

Please sign in to comment.