Skip to content

Commit e8ee340

Browse files
committed
add test
1 parent f49c123 commit e8ee340

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/interpolation_tests.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using Optim, ForwardDiff
55
using BenchmarkTools
66
using Unitful
77
using LinearAlgebra
8+
using Symbolics
89

910
function test_interpolation_type(T)
1011
@test T <: DataInterpolations.AbstractInterpolation
@@ -1110,3 +1111,30 @@ end
11101111
@test_throws ArgumentError LinearInterpolation(rand(10), rand(10))
11111112
@test_throws ArgumentError LinearInterpolation(0:10, rand(10))
11121113
end
1114+
1115+
@testset "Symbolic interpolation" begin
1116+
rng = StableRNG(50225)
1117+
1118+
t = 0.01:0.01:1.00
1119+
@variables x[1:100]
1120+
1121+
ci = ConstantInterpolation(x, t)
1122+
li = LinearInterpolation(x, t)
1123+
1124+
@test isequal(ci(0.425), x[42])
1125+
@test isequal(li(0.425), x[42] + 0.5*(x[43] - x[42]))
1126+
1127+
xvals = rand(rng, 100)
1128+
@test Symbolics.substitute(ci(0.425), Dict(x => xvals)) == xvals[42]
1129+
@test Symbolics.substitute(li(0.425), Dict(x => xvals)) == xvals[42] + 0.5*(xvals[43] - xvals[42])
1130+
1131+
@variables dx[1:100]
1132+
@test_nowarn chs = CubicHermiteSpline(dx, x, t)
1133+
@test_nowarn qi = QuadraticInterpolation(x, t)
1134+
@test_nowarn li = LagrangeInterpolation(x, t)
1135+
@test_nowarn cs = CubicSpline(x, t)
1136+
1137+
@test_throws Exception ai = AkimaInterpolation(x, t)
1138+
@test_throws Exception bsi = BSplineInterpolation(x, t, 3, :ArcLen, :Average)
1139+
@test_throws Exception pc = PCHIPInterpolation(x, t)
1140+
end

0 commit comments

Comments
 (0)