@@ -5,6 +5,7 @@ using Optim, ForwardDiff
5
5
using BenchmarkTools
6
6
using Unitful
7
7
using LinearAlgebra
8
+ using Symbolics
8
9
9
10
function test_interpolation_type (T)
10
11
@test T <: DataInterpolations.AbstractInterpolation
@@ -1125,3 +1126,30 @@ end
1125
1126
@test_throws ArgumentError LinearInterpolation (rand (10 ), rand (10 ))
1126
1127
@test_throws ArgumentError LinearInterpolation (0 : 10 , rand (10 ))
1127
1128
end
1129
+
1130
+ @testset " Symbolic interpolation" begin
1131
+ rng = StableRNG (50225 )
1132
+
1133
+ t = 0.01 : 0.01 : 1.00
1134
+ @variables x[1 : 100 ]
1135
+
1136
+ ci = ConstantInterpolation (x, t)
1137
+ li = LinearInterpolation (x, t)
1138
+
1139
+ @test isequal (ci (0.425 ), x[42 ])
1140
+ @test isequal (li (0.425 ), x[42 ] + 0.5 * (x[43 ] - x[42 ]))
1141
+
1142
+ xvals = rand (rng, 100 )
1143
+ @test Symbolics. substitute (ci (0.425 ), Dict (x => xvals)) == xvals[42 ]
1144
+ @test Symbolics. substitute (li (0.425 ), Dict (x => xvals)) == xvals[42 ] + 0.5 * (xvals[43 ] - xvals[42 ])
1145
+
1146
+ @variables dx[1 : 100 ]
1147
+ @test_nowarn chs = CubicHermiteSpline (dx, x, t)
1148
+ @test_nowarn qi = QuadraticInterpolation (x, t)
1149
+ @test_nowarn li = LagrangeInterpolation (x, t)
1150
+ @test_nowarn cs = CubicSpline (x, t)
1151
+
1152
+ @test_throws Exception ai = AkimaInterpolation (x, t)
1153
+ @test_throws Exception bsi = BSplineInterpolation (x, t, 3 , :ArcLen , :Average )
1154
+ @test_throws Exception pc = PCHIPInterpolation (x, t)
1155
+ end
0 commit comments