Skip to content

Commit 46298c9

Browse files
committed
added unit test
1 parent 778b5f5 commit 46298c9

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/integral_inverses.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ struct LinearInterpolationIntInv{uType, tType, itpType, T} <:
4141
extrapolation_right::ExtrapolationType.T
4242
iguesser::Guesser{tType}
4343
itp::itpType
44-
function LinearInterpolationIntInv(u, t, A, extrapolation_left,
45-
extrapolation_right)
44+
function LinearInterpolationIntInv(u, t, A, extrapolation_left, extrapolation_right)
4645
new{typeof(u), typeof(t), typeof(A), eltype(u)}(
4746
u, t, extrapolation_left, extrapolation_right, Guesser(t), A)
4847
end

test/integral_inverse_tests.jl

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

45
function test_integral_inverses(method; args = [], kwargs = [])
56
A = method(args...; kwargs..., extrapolation = ExtrapolationType.Extension)
@@ -22,17 +23,19 @@ end
2223

2324
function test_integral_inverse_extrapolation()
2425
# Linear function with constant extrapolation
25-
t = collect(0:4)
26-
u = [0.0, 2.0, 3.0, 4.0]
26+
t = collect(1:4)
27+
u = [1.0, 2.0, 3.0, 4.0]
2728
A = LinearInterpolation(u, t, extrapolation = ExtrapolationType.Constant)
2829

29-
A_intinv = invert_integral(A, extrapolation_left = ExtrapolationType.Extension,
30-
extrapolation_right = ExtrapolationType.Extension)
30+
A_intinv = invert_integral(A, ExtrapolationType.Extension, ExtrapolationType.Extension)
3131

3232
# for a linear function, the integral is quadratic
3333
# 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
34+
area_0_to_4 = 0.5 * 4.0^2
35+
area_4_to_5 = 4.0
36+
area = area_0_to_4 + area_4_to_5
37+
38+
@test A_intinv(area) 5.0
3639
end
3740

3841
@testset "Linear Interpolation" begin

0 commit comments

Comments
 (0)