Skip to content

Commit 9aaa42e

Browse files
committed
add simple tests for definite integration
1 parent ca1a14b commit 9aaa42e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/integral.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Output:
4646
- `unsolved`: the residual unsolved portion of the input
4747
- `err`: the numerical error in reaching the solution
4848
"""
49-
function integrate(eq, x = nothing, domain::Vector{<:Number} = nothing; abstol = 1e-6, num_steps = 2, num_trials = 10,
49+
function integrate(eq, x = nothing, domain::Vector{<:Number} = [NaN]; abstol = 1e-6, num_steps = 2, num_trials = 10,
5050
radius = 1.0,
5151
show_basis = false, opt = STLSQ(exp.(-10:1:0)), bypass = false,
5252
symbolic = true, max_basis = 100, verbose = false, complex_plane = true,
@@ -73,7 +73,7 @@ function integrate(eq, x = nothing, domain::Vector{<:Number} = nothing; abstol =
7373
s, u, ϵ = integrate_sum(eq, x, l; bypass, abstol, num_trials, num_steps,
7474
radius, show_basis, opt, symbolic,
7575
max_basis, verbose, complex_plane, use_optim)
76-
if domain != nothing
76+
if !all( domain .=== NaN )
7777
s = substitute( s, Dict( [ x=>domain[1] ] ) ) - substitute( s, Dict( [ x=>domain[2] ] ) )
7878
end
7979
# return simplify(s), u, ϵ

test/runtests.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,27 @@ function test_integrals(; kw...)
240240
return n
241241
end
242242

243+
function test_definite_integrals()
244+
miss_count = 0
245+
eqn = x
246+
val = SymbolicNumericIntegration.integrate( eqn, x, [ 0, 1 ] )[1]
247+
miss_count += ( isapprox( val, 0.5 ) ) && ( typeof( val ) == typeof( 1 ) )
248+
val = SymbolicNumericIntegration.integrate( eqn, x, [ 0.0, 1.0 ] )[1]
249+
miss_count += ( isapprox( val, 0.5 ) ) && ( typeof( val ) == typeof( 1.0 ) )
250+
val = SymbolicNumericIntegration.integrate( eqn, x, [ 0//1, 1//1 ] )[1]
251+
miss_count += ( isapprox( val, 0.5 ) ) && ( typeof( val ) == typeof( 1//1 ) )
252+
val = SymbolicNumericIntegration.integrate( eqn, x, [ Num(π), Num(2π) ] )[1]
253+
miss_count += ( isequal( val, 3*Num(π)^2/2 ) ) && ( typeof( val ) == typeof( Num(π) ) )
254+
return miss_count
255+
end
256+
243257
@testset "integral" begin
244258
n = test_integrals(; symbolic = false, verbose = false, homotopy = true, num_steps = 2,
245259
num_trials = 10)
246260
@test n > 0
247261
end
262+
263+
@testset "definite_integral" begin
264+
n = test_definite_integrals()
265+
@test n == 0
266+
end

0 commit comments

Comments
 (0)