Skip to content

Commit 9782f79

Browse files
authored
Add tests for ApproxFunBase (#111)
1 parent 1efb98a commit 9782f79

File tree

5 files changed

+94
-19
lines changed

5 files changed

+94
-19
lines changed

test/SpeedODETest.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
module SpeedODETest
12
using ApproxFunOrthogonalPolynomials, SpecialFunctions, Test
23
import ApproxFunBase: ldiv_coefficients
4+
using LinearAlgebra
35

46
## ODEs
57

@@ -113,3 +115,5 @@ u=nullspace(A)
113115
@test A[1:10,1:10] transpose(transpose(A)[1:10,1:10])
114116
@time u=nullspace(A)
115117
println("Nullspace Airy: 0.052730 seconds (75.21 k allocations: 56.736 MB)")
118+
119+
end # module

test/SpeedOperatorTest.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
module SpeedOperatorTest
12
using ApproxFunOrthogonalPolynomials, Test
23

34

@@ -29,3 +30,5 @@ A=Derivative(d)^2-x
2930
#
3031
# Profile.print()
3132
@time a*b #0.0014
33+
34+
end # module

test/SpeedPDETest.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
module SpeedPDETest
12
using ApproxFunOrthogonalPolynomials, BlockBandedMatrices, Test
2-
import ApproxFunOrthogonalPolynomials: Block
3+
import ApproxFunOrthogonalPolynomials: Block
4+
using LinearAlgebra
35

46
## PDEs
57
d=ChebyshevInterval()^2
@@ -42,3 +44,5 @@ println("Neumann Helmholtz: should be ~0.032")
4244
# @time u=PO\u0
4345
#
4446
# println("Schrodinger: should be ~0.013,0.015")
47+
48+
end # module

test/SpeedTest.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
module SpeedTest
12
using ApproxFunOrthogonalPolynomials, Test
2-
3-
43
c = rand(1000)
54
x=rand(10000)
65
f=Fun(Chebyshev,c)
@@ -38,3 +37,5 @@ roots(f)
3837
roots(f)
3938
@time roots(f)
4039
println("Roots: Time should be ~0.08")
40+
41+
end # module

test/miscAFBase.jl

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,83 @@
1+
using ApproxFunOrthogonalPolynomials
12
using ApproxFunBase
2-
@testset "ApproxFunOrthogonalPolynomials" begin
3-
@test (@inferred Fun()) == Fun(x->x, Chebyshev())
4-
@test (@inferred norm(Fun())) norm(Fun(), 2) (2/3) # √∫x^2 dx over -1..1
5-
6-
v = rand(4)
7-
v2 = transform(NormalizedChebyshev(), v)
8-
@test itransform(NormalizedChebyshev(), v2) v
9-
10-
f = @inferred Fun(x->x^2, Chebyshev())
11-
v = @inferred coefficients(f, Chebyshev(), Legendre())
12-
@test eltype(v) == eltype(coefficients(f))
13-
@test v coefficients(Fun(x->x^2, Legendre()))
14-
15-
# inference check for coefficients
16-
v = @inferred coefficients(Float64[0,0,1], Chebyshev(), Ultraspherical(1))
17-
@test v [-0.5, 0, 0.5]
3+
using Test
4+
using LinearAlgebra
5+
using StaticArrays
6+
using BandedMatrices
7+
8+
@testset "ApproxFunBase" begin
9+
@testset "Constructor" begin
10+
@test (@inferred Fun()) == Fun(x->x, Chebyshev())
11+
@test (@inferred norm(Fun())) norm(Fun(), 2) (2/3) # √∫x^2 dx over -1..1
12+
end
13+
14+
@testset "transform" begin
15+
v = rand(4)
16+
v2 = transform(NormalizedChebyshev(), v)
17+
@test itransform(NormalizedChebyshev(), v2) v
18+
19+
@testset "coefficients" begin
20+
f = @inferred Fun(x->x^2, Chebyshev())
21+
v = @inferred coefficients(f, Chebyshev(), Legendre())
22+
@test eltype(v) == eltype(coefficients(f))
23+
@test v coefficients(Fun(x->x^2, Legendre()))
24+
25+
# inference check for coefficients
26+
v = @inferred coefficients(Float64[0,0,1], Chebyshev(), Ultraspherical(1))
27+
@test v [-0.5, 0, 0.5]
28+
end
29+
end
30+
31+
@testset "multiplication inference" begin
32+
function g2()
33+
f = Fun(0..1)
34+
f * f
35+
end
36+
y = @inferred g2()(0.1)
37+
@test y (0.1)^2
38+
39+
function g3()
40+
f = Fun(0..1)
41+
f * f * f
42+
end
43+
y = @inferred g3()(0.1)
44+
@test y (0.1)^3
45+
46+
function g4()
47+
f = Fun(0..1)
48+
f * f * f * f
49+
end
50+
y = @inferred g4()(0.1)
51+
@test y (0.1)^4
52+
end
53+
54+
@testset "intpow" begin
55+
@testset "Interval" begin
56+
function h(::Val{N}) where {N}
57+
f = Fun(0..1)
58+
f^N
59+
end
60+
@test (@inferred h(Val(0)))(0.1) (0.1)^0
61+
@test (@inferred h(Val(1)))(0.1) (0.1)^1
62+
@test (@inferred h(Val(2)))(0.1) (0.1)^2
63+
@test (@inferred h(Val(3)))(0.1) (0.1)^3
64+
@test (@inferred h(Val(4)))(0.1) (0.1)^4
65+
@test h(Val(10))(0.1) (0.1)^10 rtol=1e-6
66+
end
67+
68+
@testset "ChebyshevInterval" begin
69+
function h(::Val{N}) where {N}
70+
f = Fun()
71+
f^N
72+
end
73+
@test (@inferred h(Val(0)))(0.1) (0.1)^0
74+
@test (@inferred h(Val(1)))(0.1) (0.1)^1
75+
@test (@inferred h(Val(2)))(0.1) (0.1)^2
76+
@test (@inferred h(Val(3)))(0.1) (0.1)^3
77+
@test (@inferred h(Val(4)))(0.1) (0.1)^4
78+
@test h(Val(10))(0.1) (0.1)^10 rtol=1e-6
79+
end
80+
end
1881

1982
@testset "int coeffs" begin
2083
f = Fun(Chebyshev(), [0,1])

0 commit comments

Comments
 (0)