@@ -4,6 +4,7 @@ using DataInterpolations: integral
4
4
using Optim, ForwardDiff
5
5
using RegularizationTools
6
6
using StableRNGs
7
+ using Unitful
7
8
8
9
function test_integral (method; args = [], kwargs = [], name:: String )
9
10
func = method (args... ; kwargs... , extrapolation_left = ExtrapolationType. Extension,
213
214
@test_throws DataInterpolations. IntegralNotFoundError integral (A, 1.0 , 100.0 )
214
215
@test_throws DataInterpolations. IntegralNotFoundError integral (A, 50.0 )
215
216
end
217
+
218
+ # issue #385
219
+ @testset " Integrals with unitful numbers" begin
220
+ u = rand (5 )u " m"
221
+ A = ConstantInterpolation (u, (1 : 5 )u " s" )
222
+ @test @inferred (integral (A, 4 u " s" )) ≈ sum (u[1 : 3 ]) * u " s"
223
+ end
224
+
225
+ @testset " cumulative_integral" begin
226
+ A = ConstantInterpolation ([" A" , " B" , " C" ], [0.0 , 0.25 , 0.75 ])
227
+ for cache_parameter in (true , false )
228
+ @test @inferred (DataInterpolations. cumulative_integral (A, cache_parameter)) ===
229
+ nothing
230
+ end
231
+
232
+ A = ConstantInterpolation ([3.1 , 2.5 , 4.7 ], [0.0 , 0.25 , 0.75 ])
233
+ @test @inferred (DataInterpolations. cumulative_integral (A, false )) == Float64[]
234
+ @test @inferred (DataInterpolations. cumulative_integral (A, true )) == [0.775 , 2.025 ]
235
+ end
0 commit comments