Skip to content

Commit

Permalink
Fix 2D tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolaru committed May 26, 2024
1 parent 5bc6d21 commit 9e43ee0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/IntervalRootFinding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import IntervalArithmetic: interval

include("region.jl")
export
isempty_region, intersect_region
isempty_region, intersect_region, in_region

include("root_object.jl")
include("roots.jl")
Expand Down
3 changes: 3 additions & 0 deletions src/region.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
in_region(x, Y::Interval) = in_interval(x, Y)
in_region(x::AbstractVector, Y::AbstractVector{<:Interval}) = all(in_interval.(x, Y))

function intersect_region(X::Interval, Y::Interval)
intersection = intersect_interval(bareinterval(X), bareinterval(Y))
dec = min(decoration(X), decoration(Y))
Expand Down
15 changes: 10 additions & 5 deletions test/roots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ newtonlike_methods = [Newton, Krawczyk]
end


in_solution_set(point, solution_intervals) = any(in_interval.(point, solution_intervals))
function in_solution_set(point, solution_intervals)
return any(map(Y -> in_region(point, Y), solution_intervals))
end

@testset "2D roots" begin
f(x, y) = [x^2 + y^2 - 1, y - 2x]
Expand All @@ -68,12 +70,15 @@ in_solution_set(point, solution_intervals) = any(in_interval.(point, solution_in
# Bisection
rts = roots(f, X ; contractor = Bisection, abstol = 1e-3)
exact_sol = [sqrt(1/5), 2sqrt(1/5)]
@test_broken in_solution_set(exact_sol, root_region.(rts))
@test_broken in_solution_set(-exact_sol, root_region.(rts))
@test in_solution_set(exact_sol, root_region.(rts))
@test in_solution_set(-exact_sol, root_region.(rts))

for method in newtonlike_methods
for contractor in newtonlike_methods
deriv = xx -> ForwardDiff.jacobian(f, xx)
test_newtonlike(f, deriv, X, method, 2)
test_newtonlike(f, deriv, X, contractor, 2)
rts = roots(f, X ; contractor)
@test in_solution_set(exact_sol, root_region.(rts))
@test in_solution_set(-exact_sol, root_region.(rts))
end

# Infinite interval
Expand Down

0 comments on commit 9e43ee0

Please sign in to comment.