Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bisection test more expressive #156

Merged
merged 2 commits into from
Jun 26, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion test/roots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,19 @@ newtonlike_methods = [Newton, Krawczyk]
end


in_solution_set(point, solution_intervals) =
any(map(interval -> point in interval, solution_intervals))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you remove the map and just write any(interval -> point in interval, solution_intervals), which should even be slightly more efficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct. I've adjusted the PR.


@testset "2D roots" begin
f(x, y) = SVector(x^2 + y^2 - 1, y - 2x)
f(X) = f(X...)
X = (-6..6) × (-6..6)

# Bisection
rts = roots(f, X, Bisection, 1e-3)
@test length(rts) == 4
exact_sol = [sqrt(1/5), 2sqrt(1/5)]
@test in_solution_set(exact_sol, interval.(rts))
@test in_solution_set(-exact_sol, interval.(rts))

for method in newtonlike_methods
deriv = xx -> ForwardDiff.jacobian(f, xx)
Expand Down