Skip to content

Commit

Permalink
Clean prints in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot committed Dec 21, 2023
1 parent a4a51dd commit 448b485
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
2 changes: 1 addition & 1 deletion test/allocation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function alloc_solve_model(solve, XData, H, g, ng, calls, max_calls, α)
return nothing
end

for (Data, solve) in (
@testset "Allocation test in preprocess and solvemodel" for (Data, solve) in (
(PDataKARC, AdaptiveRegularization.solve_modelKARC),
(PDataTRK, AdaptiveRegularization.solve_modelTRK),
(PDataST, AdaptiveRegularization.solve_modelST_TR),
Expand Down
46 changes: 25 additions & 21 deletions test/allocation_test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ function alloc_increase(XData, α, TR)
return nothing
end

for XData in (PDataKARC(S, T, n), PDataTRK(S, T, n), PDataST(S, T, n))
@testset "Allocation test in AdaptiveRegularization.decrease for $(typeof(XData))" begin
alloc_decrease(XData, α, TR)
al = @allocated alloc_decrease(XData, α, TR)
@test al == 0
end
@testset "Allocation test in AdaptiveRegularization.decrease for $(typeof(XData))" begin
alloc_increase(XData, α, TR)
al = @allocated alloc_increase(XData, α, TR)
@test al == 0
@testset "Allocation test in increase/decrease" begin
for XData in (PDataKARC(S, T, n), PDataTRK(S, T, n), PDataST(S, T, n))
@testset "Allocation test in decrease for $(typeof(XData))" begin
alloc_decrease(XData, α, TR)
al = @allocated alloc_decrease(XData, α, TR)
@test al == 0
end
@testset "Allocation test in increase for $(typeof(XData))" begin
alloc_increase(XData, α, TR)
al = @allocated alloc_increase(XData, α, TR)
@test al == 0
end
end
end

Expand All @@ -44,15 +46,17 @@ function alloc_hessian(who, nlp, x0)
return nothing
end

@testset "Test in-place hessian allocations" for (Workspace, limit) in (
(HessDense, 1952),
(HessSparse, 944),
(HessSparseCOO, 0),
(HessOp, 960),
)
who = Workspace(nlp, n)
alloc_hessian(who, nlp, x0)
al = @allocated alloc_hessian(who, nlp, x0)
@test al <= limit
println("Allocations for $Workspace is $al.")
@testset "Test in-place hessian allocations" begin
@testset "$Workspace" for (Workspace, limit) in (
(HessDense, 1952),
(HessSparse, 944),
(HessSparseCOO, 0),
(HessOp, 960),
)
who = Workspace(nlp, n)
alloc_hessian(who, nlp, x0)
al = @allocated alloc_hessian(who, nlp, x0)
@test al <= limit
println("Allocations for $Workspace is $al.")
end
end
29 changes: 16 additions & 13 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ end
end
end

global nbsolver = 0
for solver in ALL_solvers
global nbsolver += 1
nlp = extrosnb(n = 2)
nlpstop = NLPStopping(nlp)
println(nbsolver, " ", solver)
eval(solver)(nlpstop, verbose = true)
final_nlp_at_x, optimal = nlpstop.current_state, nlpstop.meta.optimal
@test optimal
reset!(nlp)
stats = eval(solver)(nlp, verbose = false)
@test stats.status == :first_order
reset!(nlp)
@testset "Invidivual tests on all solvers" begin
global nbsolver = 0
verbose = false # turn true for debug
@testset "Testing $solver individually" for solver in ALL_solvers
global nbsolver += 1
nlp = extrosnb(n = 2)
nlpstop = NLPStopping(nlp)
verbose && println(nbsolver, " ", solver)
eval(solver)(nlpstop, verbose = verbose)
final_nlp_at_x, optimal = nlpstop.current_state, nlpstop.meta.optimal
@test optimal
reset!(nlp)
stats = eval(solver)(nlp, verbose = verbose)
@test stats.status == :first_order
reset!(nlp)
end
end

if VERSION >= v"1.7.0"
Expand Down

0 comments on commit 448b485

Please sign in to comment.