Skip to content

Commit ab07ff7

Browse files
committed
add test for configurable extrapolation method
1 parent 23e6798 commit ab07ff7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

test/integral_inverse_tests.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using DataInterpolations
22
using DataInterpolations: integral, derivative, invert_integral
3-
using FiniteDifferences
43

54
function test_integral_inverses(method; args = [], kwargs = [])
65
A = method(args...; kwargs..., extrapolation = ExtrapolationType.Extension)
@@ -21,6 +20,21 @@ function test_integral_inverses(method; args = [], kwargs = [])
2120
@test @inferred(A(ts[37])) == A(ts[37])
2221
end
2322

23+
function test_integral_inverse_extrapolation()
24+
# Linear function with constant extrapolation
25+
t = collect(0:4)
26+
u = [0.0, 2.0, 3.0, 4.0]
27+
A = LinearInterpolation(u, t, extrapolation = ExtrapolationType.Constant)
28+
29+
A_intinv = invert_integral(A, extrapolation_left = ExtrapolationType.Extension,
30+
extrapolation_right = ExtrapolationType.Extension)
31+
32+
# for a linear function, the integral is quadratic
33+
# but the constant extrapolation part is linear.
34+
A_5 = 1 / 2 * 4.0^2 + 5.0
35+
@test A_int_inv(A_5) 5.0
36+
end
37+
2438
@testset "Linear Interpolation" begin
2539
t = collect(1:5)
2640
u = [1.0, 1.0, 2.0, 4.0, 3.0]
@@ -29,6 +43,8 @@ end
2943
u = [1.0, -1.0, 2.0, 4.0, 3.0]
3044
A = LinearInterpolation(u, t)
3145
@test_throws DataInterpolations.IntegralNotInvertibleError invert_integral(A)
46+
47+
test_integral_inverse_extrapolation()
3248
end
3349

3450
@testset "Constant Interpolation" begin

0 commit comments

Comments
 (0)