|
| 1 | +using SimpleNonlinearSolve, LinearAlgebra, NonlinearProblemLibrary, Test |
| 2 | + |
| 3 | +problems = NonlinearProblemLibrary.problems |
| 4 | +dicts = NonlinearProblemLibrary.dicts |
| 5 | + |
| 6 | +function test_on_library(problems, dicts, alg_ops, broken_tests, ϵ = 1e-4; |
| 7 | + skip_tests = nothing) |
| 8 | + for (idx, (problem, dict)) in enumerate(zip(problems, dicts)) |
| 9 | + x = dict["start"] |
| 10 | + res = similar(x) |
| 11 | + nlprob = NonlinearProblem(problem, copy(x)) |
| 12 | + @testset "$idx: $(dict["title"])" begin |
| 13 | + for alg in alg_ops |
| 14 | + try |
| 15 | + sol = solve(nlprob, alg; |
| 16 | + termination_condition = AbsNormTerminationMode()) |
| 17 | + problem(res, sol.u, nothing) |
| 18 | + |
| 19 | + skip = skip_tests !== nothing && idx in skip_tests[alg] |
| 20 | + if skip |
| 21 | + @test_skip norm(res) ≤ ϵ |
| 22 | + continue |
| 23 | + end |
| 24 | + broken = idx in broken_tests[alg] ? true : false |
| 25 | + @test norm(res)≤ϵ broken=broken |
| 26 | + catch |
| 27 | + broken = idx in broken_tests[alg] ? true : false |
| 28 | + if broken |
| 29 | + @test false broken=true |
| 30 | + else |
| 31 | + @test 1 == 2 |
| 32 | + end |
| 33 | + end |
| 34 | + end |
| 35 | + end |
| 36 | + end |
| 37 | +end |
| 38 | + |
| 39 | +@testset "SimpleNewtonRaphson 23 Test Problems" begin |
| 40 | + alg_ops = (SimpleNewtonRaphson(),) |
| 41 | + |
| 42 | + # dictionary with indices of test problems where method does not converge to small residual |
| 43 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 44 | + broken_tests[alg_ops[1]] = [6] |
| 45 | + |
| 46 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 47 | +end |
| 48 | + |
| 49 | +@testset "SimpleTrustRegion 23 Test Problems" begin |
| 50 | + alg_ops = (SimpleTrustRegion(),) |
| 51 | + |
| 52 | + # dictionary with indices of test problems where method does not converge to small residual |
| 53 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 54 | + broken_tests[alg_ops[1]] = [3, 6, 15, 16, 21] |
| 55 | + |
| 56 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 57 | +end |
| 58 | + |
| 59 | +@testset "SimpleDFSane 23 Test Problems" begin |
| 60 | + alg_ops = (SimpleDFSane(),) |
| 61 | + |
| 62 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 63 | + broken_tests[alg_ops[1]] = [1, 2, 3, 4, 5, 6, 7, 9, 11, 12, 13, 15, 16, 17, 21, 22] |
| 64 | + |
| 65 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 66 | +end |
| 67 | + |
| 68 | +@testset "SimpleBroyden 23 Test Problems" begin |
| 69 | + alg_ops = (SimpleBroyden(),) |
| 70 | + |
| 71 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 72 | + broken_tests[alg_ops[1]] = [1, 2, 4, 5, 6, 11, 12, 13, 14] |
| 73 | + |
| 74 | + skip_tests = Dict(alg => Int[] for alg in alg_ops) |
| 75 | + skip_tests[alg_ops[1]] = [22] |
| 76 | + |
| 77 | + test_on_library(problems, dicts, alg_ops, broken_tests; skip_tests) |
| 78 | +end |
| 79 | + |
| 80 | +@testset "SimpleKlement 23 Test Problems" begin |
| 81 | + alg_ops = (SimpleKlement(),) |
| 82 | + |
| 83 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 84 | + broken_tests[alg_ops[1]] = [1, 2, 4, 5, 6, 7, 9, 10, 11, 12, 13, 19, 21, 22] |
| 85 | + |
| 86 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 87 | +end |
0 commit comments