|
| 1 | +@testsnippet RobustnessTestSnippet begin |
| 2 | + using NonlinearProblemLibrary, NonlinearSolveBase, LinearAlgebra |
| 3 | + |
| 4 | + problems = NonlinearProblemLibrary.problems |
| 5 | + dicts = NonlinearProblemLibrary.dicts |
| 6 | + |
| 7 | + function test_on_library( |
| 8 | + problems, dicts, alg_ops, broken_tests, ϵ = 1e-4; skip_tests = nothing) |
| 9 | + for (idx, (problem, dict)) in enumerate(zip(problems, dicts)) |
| 10 | + x = dict["start"] |
| 11 | + res = similar(x) |
| 12 | + nlprob = NonlinearProblem(problem, copy(x)) |
| 13 | + @testset "$idx: $(dict["title"])" begin |
| 14 | + for alg in alg_ops |
| 15 | + try |
| 16 | + sol = solve(nlprob, alg; |
| 17 | + termination_condition = AbsNormTerminationMode(norm)) |
| 18 | + problem(res, sol.u, nothing) |
| 19 | + |
| 20 | + skip = skip_tests !== nothing && idx in skip_tests[alg] |
| 21 | + if skip |
| 22 | + @test_skip norm(res) ≤ ϵ |
| 23 | + continue |
| 24 | + end |
| 25 | + broken = idx in broken_tests[alg] ? true : false |
| 26 | + @test norm(res)≤ϵ broken=broken |
| 27 | + catch e |
| 28 | + @error e |
| 29 | + broken = idx in broken_tests[alg] ? true : false |
| 30 | + if broken |
| 31 | + @test false broken=true |
| 32 | + else |
| 33 | + @test 1 == 2 |
| 34 | + end |
| 35 | + end |
| 36 | + end |
| 37 | + end |
| 38 | + end |
| 39 | + end |
| 40 | +end |
| 41 | + |
| 42 | +@testitem "23 Test Problems: SimpleNewtonRaphson" setup=[RobustnessTestSnippet] tags=[:core] begin |
| 43 | + alg_ops = (SimpleNewtonRaphson(),) |
| 44 | + |
| 45 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 46 | + broken_tests[alg_ops[1]] = [] |
| 47 | + |
| 48 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 49 | +end |
| 50 | + |
| 51 | +@testitem "23 Test Problems: SimpleHalley" setup=[RobustnessTestSnippet] tags=[:core] begin |
| 52 | + alg_ops = (SimpleHalley(),) |
| 53 | + |
| 54 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 55 | + if Sys.isapple() |
| 56 | + broken_tests[alg_ops[1]] = [1, 5, 11, 15, 16, 18] |
| 57 | + else |
| 58 | + broken_tests[alg_ops[1]] = [1, 5, 15, 16, 18] |
| 59 | + end |
| 60 | + |
| 61 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 62 | +end |
| 63 | + |
| 64 | +@testitem "23 Test Problems: SimpleTrustRegion" setup=[RobustnessTestSnippet] tags=[:core] begin |
| 65 | + alg_ops = (SimpleTrustRegion(), SimpleTrustRegion(; nlsolve_update_rule = Val(true))) |
| 66 | + |
| 67 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 68 | + broken_tests[alg_ops[1]] = [3, 15, 16, 21] |
| 69 | + broken_tests[alg_ops[2]] = [15, 16] |
| 70 | + |
| 71 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 72 | +end |
| 73 | + |
| 74 | +@testitem "23 Test Problems: SimpleDFSane" setup=[RobustnessTestSnippet] tags=[:core] begin |
| 75 | + alg_ops = (SimpleDFSane(),) |
| 76 | + |
| 77 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 78 | + if Sys.isapple() |
| 79 | + broken_tests[alg_ops[1]] = [1, 2, 3, 5, 6, 21] |
| 80 | + else |
| 81 | + broken_tests[alg_ops[1]] = [1, 2, 3, 4, 5, 6, 11, 21] |
| 82 | + end |
| 83 | + |
| 84 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 85 | +end |
| 86 | + |
| 87 | +@testitem "23 Test Problems: SimpleBroyden" setup=[RobustnessTestSnippet] tags=[:core] begin |
| 88 | + alg_ops = (SimpleBroyden(),) |
| 89 | + |
| 90 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 91 | + broken_tests[alg_ops[1]] = [1, 5, 11] |
| 92 | + |
| 93 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 94 | +end |
| 95 | + |
| 96 | +@testitem "23 Test Problems: SimpleKlement" setup=[RobustnessTestSnippet] tags=[:core] begin |
| 97 | + alg_ops = (SimpleKlement(),) |
| 98 | + |
| 99 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 100 | + broken_tests[alg_ops[1]] = [1, 2, 4, 5, 11, 12, 22] |
| 101 | + |
| 102 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 103 | +end |
0 commit comments