Skip to content

Commit

Permalink
test: bring over more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 7, 2024
1 parent a753186 commit fcca2f7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/CI_SimpleNonlinearSolve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
- ubuntu-latest
- macos-latest
- windows-latest
group:
- core
- adjoint
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
Expand Down Expand Up @@ -60,6 +63,8 @@ jobs:
Pkg.instantiate()
Pkg.test(; coverage=true)
shell: julia --color=yes --code-coverage=user --depwarn=yes --project=lib/SimpleNonlinearSolve {0}
env:
GROUP: ${{ matrix.group }}
- uses: julia-actions/julia-processcoverage@v1
with:
directories: lib/SimpleNonlinearSolve/src,lib/SimpleNonlinearSolve/ext
Expand Down
40 changes: 40 additions & 0 deletions lib/SimpleNonlinearSolve/test/core/allocation_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@itesitem "Allocation Tests" tags=[:core] begin
using SimpleNonlinearSolve, StaticArrays, AllocCheck

quadratic_f(u, p) = u .* u .- p
quadratic_f!(du, u, p) = (du .= u .* u .- p)

@testset "$(nameof(typeof(alg)))" for alg in (
SimpleNewtonRaphson(),
SimpleTrustRegion(),
SimpleTrustRegion(; nlsolve_update_rule = Val(true)),
SimpleBroyden(),
SimpleLimitedMemoryBroyden(),
SimpleKlement(),
SimpleHalley(),
SimpleBroyden(; linesearch = Val(true)),
SimpleLimitedMemoryBroyden(; linesearch = Val(true))
)
@check_allocs nlsolve(prob, alg) = SciMLBase.solve(prob, alg; abstol = 1e-9)

nlprob_scalar = NonlinearProblem{false}(quadratic_f, 1.0, 2.0)
nlprob_sa = NonlinearProblem{false}(quadratic_f, @SVector[1.0, 1.0], 2.0)

try
nlsolve(nlprob_scalar, alg)
@test true
catch e
@error e
@test false
end

# ForwardDiff allocates for hessian since we don't propagate the chunksize
try
nlsolve(nlprob_sa, alg)
@test true
catch e
@error e
@test false broken = (alg isa SimpleHalley)
end
end
end
19 changes: 19 additions & 0 deletions lib/SimpleNonlinearSolve/test/core/matrix_resizing_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@testitem "Matrix Resizing" tags=[:core] begin
ff(u, p) = u .* u .- p
u0 = ones(2, 3)
p = 2.0
vecprob = NonlinearProblem(ff, vec(u0), p)
prob = NonlinearProblem(ff, u0, p)

@testset "$(nameof(typeof(alg)))" for alg in (
SimpleKlement(),
SimpleBroyden(),
SimpleNewtonRaphson(),
SimpleDFSane(),
SimpleLimitedMemoryBroyden(; threshold = Val(2)),
SimpleTrustRegion(),
SimpleTrustRegion(; nlsolve_update_rule = Val(true))
)
@test vec(solve(prob, alg).u) solve(vecprob, alg).u
end
end

0 comments on commit fcca2f7

Please sign in to comment.