-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patched bisection newton method tests (#325)
* test_newton_bisection_methods * Test newton_method_bissection_method * runtests_modified --------- Co-authored-by: Alexis Vuille <alexis.vuille@uclouvain.be> Co-authored-by: adrienbanse <adrien.banse@gmail.com>
- Loading branch information
1 parent
69580d5
commit 1b9f0e4
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
Submodule Dionysos.jl
added at
de849a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Test | ||
using Dionysos | ||
bisection = Dionysos.Utils.bisection | ||
|
||
# Define the test function, its derivative, and second derivative | ||
@testset "Bissection" begin | ||
# Define a test function | ||
test_function(x) = x^2 - 4 | ||
ϵ = 1e-6 | ||
|
||
# Call the bisection function | ||
result = bisection(test_function; interval = [0, 4], δ = ϵ, verbose = false) | ||
@test isapprox(result[1], -4.0; atol = ϵ) && 0 ≤ result[2] ≤ 4 | ||
|
||
result = bisection(test_function; interval = [0, 4], δ = ϵ, verbose = true) | ||
@test isapprox(result[1], -4.0; atol = ϵ) && 0 ≤ result[2] ≤ 4 | ||
|
||
result = bisection(test_function; interval = [1, 3], δ = ϵ, verbose = true) | ||
@test isapprox(result[1], -3.0; atol = ϵ) && 0 ≤ result[2] ≤ 4 | ||
|
||
result = bisection( | ||
test_function; | ||
interval = [-5, 4], | ||
δ = ϵ, | ||
verbose = false, | ||
stopIfNegative = true, | ||
) | ||
@test (-5 ≤ result[2] ≤ 4) && abs(result[1] + 4.0) > ϵ && result[1] < 0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Test | ||
using Dionysos | ||
newton_method = Dionysos.Utils.newton_method | ||
|
||
# Define the test function, its derivative, and second derivative | ||
@testset "EllipsoidBasics" begin | ||
f(x) = x^2 - 4 | ||
df(x) = 2x | ||
ddf(x) = 2 | ||
|
||
# Test parameters | ||
interval = [1, 3] | ||
x0 = 1.5 | ||
ϵ = 1e-6 | ||
|
||
# Call the newton_method function with the test parameters | ||
result = newton_method( | ||
f, | ||
df, | ||
ddf; | ||
interval = interval, | ||
x0 = x0, | ||
ϵ = ϵ, | ||
verbose = false, | ||
stopIfNegative = false, | ||
) | ||
# Check the result | ||
@test isapprox(result[1], -3.0; atol = ϵ) && interval[1] ≤ result[2] ≤ interval[2] | ||
|
||
result = newton_method( | ||
f, | ||
df, | ||
ddf; | ||
interval = [0, 4], | ||
x0 = x0, | ||
ϵ = ϵ, | ||
verbose = false, | ||
stopIfNegative = false, | ||
) | ||
@test isapprox(result[1], -4.0; atol = ϵ) && 0 ≤ result[2] ≤ 4 | ||
end |