Skip to content

Commit

Permalink
test: update integral tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sathvikbhagavan committed Nov 24, 2023
1 parent cf76d19 commit 1067954
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions test/integral_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ function test_integral(method, u, t; args = [], kwargs = [], name::String)
@test isapprox(qint, aint, atol = 1e-8)

# integral(A, t)
qint, err = quadgk(func, t1, (t1 + t2)/2; atol = 1e-12, rtol = 1e-12)
aint = integral(func, (t1 + t2)/2)
qint, err = quadgk(func, t1, (t1 + t2) / 2; atol = 1e-12, rtol = 1e-12)
aint = integral(func, (t1 + t2) / 2)
@test isapprox(qint, aint, atol = 1e-8)

# integrals with extrapolation
qint, err = quadgk(func, t1-5.0, (t1 + t2)/2; atol = 1e-12, rtol = 1e-12)
aint = integral(func, t1-5.0, (t1 + t2)/2)
qint, err = quadgk(func, t1 - 5.0, (t1 + t2) / 2; atol = 1e-12, rtol = 1e-12)
aint = integral(func, t1 - 5.0, (t1 + t2) / 2)
@test isapprox(qint, aint, atol = 1e-8)

qint, err = quadgk(func, (t1 + t2)/2, t2+5.0; atol = 1e-12, rtol = 1e-12)
aint = integral(func, (t1 + t2)/2, t2+5.0)
qint, err = quadgk(func, (t1 + t2) / 2, t2 + 5.0; atol = 1e-12, rtol = 1e-12)
aint = integral(func, (t1 + t2) / 2, t2 + 5.0)
@test isapprox(qint, aint, atol = 1e-8)
end
func = method(u, t, args...; kwargs...)
Expand All @@ -48,7 +48,11 @@ end
test_integral(QuadraticInterpolation, u, t; name = "Quadratic Interpolation (Vector)")
u = [3.0, 0.0, 3.0, 0.0]
t = [1.0, 2.0, 3.0, 4.0]
test_integral(QuadraticInterpolation, u, t; args = [:Backward], name = "Quadratic Interpolation (Vector)")
test_integral(QuadraticInterpolation,
u,
t;
args = [:Backward],
name = "Quadratic Interpolation (Vector)")
end

@testset "LagrangeInterpolation" begin
Expand Down Expand Up @@ -95,7 +99,11 @@ end
idx = sortperm(t)
tₒ = t[idx]
uₒ = u[idx]
test_integral(RegularizationSmooth, uₒ, tₒ; kwargs = [:alg => :fixed], name = "RegularizationSmooth")
test_integral(RegularizationSmooth,
uₒ,
tₒ;
kwargs = [:alg => :fixed],
name = "RegularizationSmooth")
end

@testset "Curvefit" begin
Expand All @@ -108,3 +116,19 @@ end
@test_throws DataInterpolations.IntegralNotFoundError integral(A, 0.0, 1.0)
@test_throws DataInterpolations.IntegralNotFoundError integral(A, 5.0)
end

@testset "BSplineInterpolation" begin
t = [0, 62.25, 109.66, 162.66, 205.8, 252.3]
u = [14.7, 11.51, 10.41, 14.95, 12.24, 11.22]
A = BSplineInterpolation(u, t, 2, :Uniform, :Uniform)
@test_throws DataInterpolations.IntegralNotFoundError integral(A, 1.0, 100.0)
@test_throws DataInterpolations.IntegralNotFoundError integral(A, 50.0)
end

@testset "BSplineApprox" begin
t = [0, 62.25, 109.66, 162.66, 205.8, 252.3]
u = [14.7, 11.51, 10.41, 14.95, 12.24, 11.22]
A = BSplineApprox(u, t, 2, 4, :Uniform, :Uniform)
@test_throws DataInterpolations.IntegralNotFoundError integral(A, 1.0, 100.0)
@test_throws DataInterpolations.IntegralNotFoundError integral(A, 50.0)
end

0 comments on commit 1067954

Please sign in to comment.