Skip to content

Commit

Permalink
test: test values of solved roots
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Nov 6, 2024
1 parent bbcacd3 commit 1d71dd4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,25 @@ end
expr = sec(x ^ 2 + 4x + 4) ^ 3 - 3
roots = ia_solve(expr, x)
@test length(roots) == 6 # 2 quadratic roots * 3 roots from cbrt(3)
@test length(Symbolics.get_variables(roots[1])) == 1
_n = only(Symbolics.get_variables(roots[1]))
vals = substitute.(roots, (Dict(_n => 0),))
@test all(x -> isapprox(norm(sec(x^2 + 4x + 4) ^ 3 - 3), 0.0, atol = 1e-14), vals)

roots = ia_solve(expr, x; complex_roots = false)
@test length(roots) == 2
# the `n` in `θ + n * 2π`
@test length(Symbolics.get_variables(roots[1])) == 1
@test length(Symbolics.get_variables(roots[2])) == 1
_n = only(Symbolics.get_variables(roots[1]))
vals = substitute.(roots, (Dict(_n => 0),))
@test all(x -> isapprox(norm(sec(x^2 + 4x + 4) ^ 3 - 3), 0.0, atol = 1e-14), vals)

roots = ia_solve(expr, x; complex_roots = false, periodic_roots = false)
@test length(roots) == 2
@test length(Symbolics.get_variables(roots[1])) == 0
@test length(Symbolics.get_variables(roots[2])) ==0
@test_nowarn eval.(Symbolics.toexpr.(roots))
@test length(Symbolics.get_variables(roots[2])) == 0
vals = eval.(Symbolics.toexpr.(roots))
@test all(x -> isapprox(norm(sec(x^2 + 4x + 4) ^ 3 - 3), 0.0, atol = 1e-14), vals)
end
end

Expand Down

0 comments on commit 1d71dd4

Please sign in to comment.