Skip to content

Commit

Permalink
test FMinimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
lxvm authored and yuyichao committed Jan 6, 2024
1 parent f02ba90 commit 2b2e2ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/minimization.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Test
using GSL

@testset "1d minimization" begin
f = x -> cos(x) + one(x)
@testset "fminimizer $name" for (alg, name) in [
(gsl_min_fminimizer_goldensection, "goldensection")
(gsl_min_fminimizer_brent, "brent")
(gsl_min_fminimizer_quad_golden, "quad-golden")
]
m, m_exact = 2.0, pi
a, b = 0.0, 6.0
epsabs, epsrel = 1e-3, 0e-0
s = GSLMinFMinimizer(alg)
@test min_fminimizer_name(s) == name
min_fminimizer_set(s, f, m, a, b)

maxiter = 100
status = converged = 0
for i in 1:maxiter
status = min_fminimizer_iterate(s)
m = min_fminimizer_x_minimum(s)
a = min_fminimizer_x_lower(s)
b = min_fminimizer_x_upper(s)
converged = min_test_interval(a, b, epsabs, epsrel)
status == converged == GSL_SUCCESS && break
end
@test status == converged == GSL_SUCCESS
@test m m_exact atol=epsabs rtol=epsrel
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Random.seed!(1)
include("rootfinding.jl")
include("specfunc.jl")
include("chebyshev.jl")
include("minimization.jl")
end

0 comments on commit 2b2e2ae

Please sign in to comment.