Skip to content

Commit

Permalink
test: add second order derivative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sathvikbhagavan committed Apr 28, 2024
1 parent 11db3b3 commit 2ae1f4a
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions test/derivative_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,45 @@ function test_derivatives(method, u, t; args = [], kwargs = [], name::String)
cdiff = central_fdm(5, 1; geom = true)(func, _t)
adiff = derivative(func, _t)
@test isapprox(cdiff, adiff, atol = 1e-8)
adiff2 = derivative(func, _t; order = 2)
cdiff2 = central_fdm(5, 1; geom = true)(t -> derivative(func, t), _t)
@test isapprox(cdiff2, adiff2, atol = 1e-8)
end

# Interpolation time points
for _t in t[2:(end - 1)]
fdiff = if func isa BSplineInterpolation || func isa BSplineApprox
forward_fdm(5, 1; geom = true)(func, _t)
if func isa BSplineInterpolation || func isa BSplineApprox
fdiff = forward_fdm(5, 1; geom = true)(func, _t)
fdiff2 = forward_fdm(5, 1; geom = true)(t -> derivative(func, t), _t)
else
backward_fdm(5, 1; geom = true)(func, _t)
fdiff = backward_fdm(5, 1; geom = true)(func, _t)
fdiff2 = backward_fdm(5, 1; geom = true)(t -> derivative(func, t), _t)
end
adiff = derivative(func, _t)
adiff2 = derivative(func, _t; order = 2)
@test isapprox(fdiff, adiff, atol = 1e-8)
@test isapprox(fdiff2, adiff2, atol = 1e-8)
end

# t = t0
fdiff = forward_fdm(5, 1; geom = true)(func, t[1])
adiff = derivative(func, t[1])
@test isapprox(fdiff, adiff, atol = 1e-8)
if !(func isa BSplineInterpolation || func isa BSplineApprox)
fdiff2 = forward_fdm(5, 1; geom = true)(t -> derivative(func, t), t[1])
adiff2 = derivative(func, t[1]; order = 2)
@test isapprox(fdiff2, adiff2, atol = 1e-8)
end

# t = tend
fdiff = backward_fdm(5, 1; geom = true)(func, t[end])
adiff = derivative(func, t[end])
@test isapprox(fdiff, adiff, atol = 1e-8)
if !(func isa BSplineInterpolation || func isa BSplineApprox)
fdiff2 = backward_fdm(5, 1; geom = true)(t -> derivative(func, t), t[end])
adiff2 = derivative(func, t[end]; order = 2)
@test isapprox(fdiff2, adiff2, atol = 1e-8)
end
end
func = method(u, t, args...)
@test_throws DataInterpolations.ExtrapolationError derivative(func, t[1] - 1.0)
Expand Down

0 comments on commit 2ae1f4a

Please sign in to comment.