From 736b4a36ee75e5566fce3a98c3a3bd0b8789e97d Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Fri, 27 Sep 2024 15:29:07 -0400 Subject: [PATCH] test: issue 451 --- test/misc/issues_tests.jl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/misc/issues_tests.jl diff --git a/test/misc/issues_tests.jl b/test/misc/issues_tests.jl new file mode 100644 index 000000000..24e39943c --- /dev/null +++ b/test/misc/issues_tests.jl @@ -0,0 +1,22 @@ +@testitem "Issue #451" tags=[:misc] begin + f(u, p) = u^2 - p + + jac_calls = 0 + function df(u, p) + global jac_calls += 1 + return 2u + end + + fn = NonlinearFunction(f; jac = df) + prob = NonlinearProblem(fn, 1.0, 2.0) + sol = solve(prob, NewtonRaphson()) + @test sol.retcode == ReturnCode.Success + @test jac_calls ≥ 1 + + jac_calls = 0 + fn2 = NonlinearFunction(f) + prob = NonlinearProblem(fn2, 1.0, 2.0) + sol = solve(prob, NewtonRaphson()) + @test sol.retcode == ReturnCode.Success + @test jac_calls == 0 +end