Skip to content

Commit

Permalink
Make tests Julia 1.0 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
fgasdia committed Dec 19, 2020
1 parent 433cfee commit 48da2f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Romberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ is a prime number, it is nearly equivalent to the trapezoidal rule without extra
# Examples
```jldoctest
julia> x = range(0, π, length=2^8+1);
julia> x = range(0, stop=π, length=2^8+1);
julia> romberg(x, sin.(x))
(2.0000000000000018, 1.9984014443252818e-15)
Expand Down
24 changes: 12 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ using Romberg, Test

@testset "Romberg.jl" begin
# Test interfaces
x = range(0, π, length=2^8+1)
x = range(0, stop=π, length=2^8+1)
y = sin.(x)

@test romberg(x, y) == romberg(x, y, maxeval=9)

# Test ispow2(length(x) - 1) == false
x = range(0, π, length=2^8)
x = range(0, stop=π, length=2^8)
y = sin.(x)
@test romberg(x, y)[1] 2 rtol=1e-12

x = range(0, π, length=2^8-1)
x = range(0, stop=π, length=2^8-1)
y = sin.(x)
@test romberg(x, y)[1] 2 rtol=1e-9

Expand All @@ -22,31 +22,31 @@ using Romberg, Test
@test romberg(x, y)[1] == 0

# Test length(x) == 2
x = range(0, 1, length=2)
x = range(0, stop=1, length=2)
y = x.^2
@test romberg(x,y)[1] == 0.5 # integration is inaccurate

# Test length(x) == 3
x = range(0, 1, length=3)
x = range(0, stop=1, length=3)
y = x.^2
@test romberg(x, y)[1] 1/3 rtol=3e-16 # should be exact up to roundoff error

# Integrate different functions
x = range(0, π, length=2^8+1)
x = range(0, stop=π, length=2^8+1)
y = sin.(x)
@test romberg(x, y)[1] 2 rtol=1e-15

x = range(0, 1, length=2^8+1)
x = range(0, stop=1, length=2^8+1)
y = x.^3
@test romberg(x, y)[1] 1/4 rtol=3e-16 # should be exact up to roundoff error

x = range(0, π/2, length=2^5+1)
x = range(0, stop=π/2, length=2^5+1)
y = sin.(x).^2
@test romberg(x, y)[1] π/4 rtol=1e-15

m = 3
n = 4
x = range(0, π, length=2^8+1)
x = range(0, stop=π, length=2^8+1)
y = sin.(m*x).*cos.(n*x)
v = romberg(x, y)
@test v[1] 2*m/(m^2 - n^2) rtol=1e-13
Expand All @@ -57,18 +57,18 @@ using Romberg, Test

# this one requires lots of samples...
a = 15
x = range(0, a, length=2^16+1)
x = range(0, stop=a, length=2^16+1)
y = sqrt.(a^2 .- x.^2)
@test romberg(x, y)[1] π*a^2/4 rtol=1e-8
# we can do much better if we put in the correct convergence
# rate for this singular integrand, but this requires some
# understanding of the theory that most people won't have…
x = range(0, a, length=2^7+1)
x = range(0, stop=a, length=2^7+1)
y = sqrt.(a^2 .- x.^2)
@test romberg(x, y, power=0.5)[1] π*a^2/4 rtol=1e-8

# tricky to integrate
x = range(1e-15, 1, length=2^16+1)
x = range(1e-15, stop=1, length=2^16+1)
y = log.(x)./(1 .+ x)
@test romberg(x, y)[1] -π^2/12 atol=1e-4

Expand Down

0 comments on commit 48da2f3

Please sign in to comment.