Skip to content

Commit aeaae2f

Browse files
committed
Clean up tests
Test round tripping in backwards tests instead of testing against the slow naive Fourier transform. Also, make sure that ifft and irfft is fully tested.
1 parent a546280 commit aeaae2f

File tree

7 files changed

+57
-60
lines changed

7 files changed

+57
-60
lines changed

test/onedim/complex_backward.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ end
1010

1111
@testset "More backward tests. Size: $n" for n in 1:64
1212
x = complex.(randn(n), randn(n))
13+
# Assuming that fft works since it is tested independently
14+
y = fft(x)
1315

14-
@testset "against naive implementation" begin
15-
@test naive_1d_fourier_transform(x, FFTA.FFT_BACKWARD) bfft(x)
16+
@testset "round tripping with ifft" begin
17+
@test ifft(y) x
1618
end
1719

1820
@testset "allocation regression" begin
19-
@test (@test_allocations bfft(x)) <= 47
21+
@test (@test_allocations bfft(y)) <= 47
2022
end
2123
end
2224

2325
@testset "error messages" begin
24-
@test_throws DimensionMismatch bfft(zeros(0))
26+
@test_throws DimensionMismatch bfft(complex.(zeros(0)))
2527
end

test/onedim/complex_forward.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using FFTA, Test
77
y_ref[1] = N
88
@test y y_ref atol=1e-12
99
@test_broken y == fft(reshape(x,1,1,N),3)[1,1,:]
10-
@test y == fft(reshape(x,N,1),1)[:,1]
10+
@test y == fft(reshape(x,N,1), 1)[:,1]
1111
end
1212

1313
@testset "More forward tests. Size: $n" for n in 1:64

test/onedim/real_backward.jl

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using FFTA, Test, LinearAlgebra
22

33
@testset "backward. N=$N" for N in [8, 11, 15, 16, 27, 100]
4-
x = ones(Float64, N)
4+
x = ones(Complex{Float64}, N)
55
y = brfft(x, 2*(N-1))
66
y_ref = 0*y
77
y_ref[1] = 2*(N-1)
@@ -13,23 +13,16 @@ using FFTA, Test, LinearAlgebra
1313
end
1414

1515
@testset "More backward tests. Size: $n" for n in 1:64
16-
x = complex.(randn(n ÷ 2 + 1), randn(n ÷ 2 + 1))
17-
x[begin] = real(x[begin])
18-
if iseven(n)
19-
x[end] = real(x[end])
20-
xe = [x; conj.(reverse(x[begin + 1:end - 1]))]
21-
else
22-
xe = [x; conj.(reverse(x[begin + 1:end]))]
23-
end
16+
x = randn(n)
17+
# Assuming that rfft works since it is tested separately
18+
y = rfft(x)
2419

25-
@testset "against naive implementation" begin
26-
new_x = brfft(x, n)
27-
@test naive_1d_fourier_transform(xe, FFTA.FFT_BACKWARD) new_x
28-
@test new_x isa Array{<:Real}
20+
@testset "round tripping with irfft" begin
21+
@test irfft(y, n) x
2922
end
3023

3124
@testset "allocation regression" begin
32-
@test (@test_allocations brfft(x, n)) <= 55
25+
@test (@test_allocations brfft(y, n)) <= 55
3326
end
3427
end
3528

test/onedim/real_forward.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ end
1212

1313
@testset "More forward tests. Size: $n" for n in 1:64
1414
x = randn(n)
15+
y = rfft(x)
1516

1617
@testset "against naive implementation" begin
17-
y = rfft(x)
1818
@test naive_1d_fourier_transform(x, FFTA.FFT_FORWARD)[1:(n ÷ 2 + 1)] y
19+
end
1920

20-
@testset "temporarily test real dft separately until used by rfft" begin
21-
y_dft = similar(y)
22-
FFTA.fft_dft!(y_dft, x, n, 1, 1, 1, 1, cispi(-2/n))
23-
@test y y_dft
24-
end
21+
@testset "temporarily test real dft separately until used by rfft" begin
22+
y_dft = similar(y)
23+
FFTA.fft_dft!(y_dft, x, n, 1, 1, 1, 1, cispi(-2/n))
24+
@test y y_dft
2525
end
2626

2727
@testset "allocation regression" begin
@@ -31,4 +31,4 @@ end
3131

3232
@testset "error messages" begin
3333
@test_throws DimensionMismatch rfft(zeros(0))
34-
end
34+
end

test/runtests.jl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,39 @@ Random.seed!(1)
5151
include("qa/explicit_imports.jl")
5252
end
5353
@testset verbose = true "1D" begin
54-
@testset verbose = false "Complex" begin
55-
include("onedim/complex_forward.jl")
56-
include("onedim/complex_backward.jl")
57-
x = rand(ComplexF64, 100)
58-
y = fft(x)
59-
x2 = bfft(y)/length(x)
60-
@test x x2 atol=1e-12
54+
@testset verbose = true "Complex" begin
55+
@testset verbose = false "Forward" begin
56+
include("onedim/complex_forward.jl")
57+
end
58+
@testset verbose = false "Backward" begin
59+
include("onedim/complex_backward.jl")
60+
end
6161
end
62-
@testset verbose = false "Real" begin
63-
include("onedim/real_forward.jl")
64-
include("onedim/real_backward.jl")
65-
x = rand(Float64, 100)
66-
y = fft(x)
67-
x2 = bfft(y)/length(x)
68-
@test x x2 atol=1e-12
62+
@testset verbose = true "Real" begin
63+
@testset verbose = false "Forward" begin
64+
include("onedim/real_forward.jl")
65+
end
66+
@testset verbose = false "Backward" begin
67+
include("onedim/real_backward.jl")
68+
end
6969
end
7070
end
71-
@testset verbose = false "2D" begin
71+
@testset verbose = true "2D" begin
7272
@testset verbose = true "Complex" begin
73-
include("twodim/complex_forward.jl")
74-
include("twodim/complex_backward.jl")
75-
x = rand(ComplexF64, 100, 100)
76-
y = fft(x)
77-
x2 = bfft(y)/length(x)
78-
@test x x2
73+
@testset verbose = false "Forward" begin
74+
include("twodim/complex_forward.jl")
75+
end
76+
@testset verbose = false "Backward" begin
77+
include("twodim/complex_backward.jl")
78+
end
7979
end
8080
@testset verbose = true "Real" begin
81-
include("twodim/real_forward.jl")
82-
include("twodim/real_backward.jl")
83-
x = rand(Float64, 100, 100)
84-
y = fft(x)
85-
x2 = bfft(y)/length(x)
86-
@test x x2
81+
@testset verbose = false "Forward" begin
82+
include("twodim/real_forward.jl")
83+
end
84+
@testset verbose = false "Backward" begin
85+
include("twodim/real_backward.jl")
86+
end
8787
end
8888
end
8989
end

test/twodim/complex_backward.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ end
1010

1111
@testset "More backward tests" for n in 1:64
1212
@testset "size: ($m, $n)" for m in n:(n + 1)
13-
X = complex.(randn(m, n), randn(m, n))
13+
x = complex.(randn(n), randn(n))
14+
# Assuming that fft works since it is tested independently
15+
y = fft(x)
1416

15-
@testset "against naive implementation" begin
16-
@test naive_2d_fourier_transform(X, FFTA.FFT_BACKWARD) bfft(X)
17+
@testset "round tripping with ifft" begin
18+
@test ifft(y) x
1719
end
1820

1921
@testset "allocations" begin
20-
@test (@test_allocations bfft(X)) <= 116
22+
@test (@test_allocations bfft(y)) <= 116
2123
end
2224
end
2325
end

test/twodim/real_backward.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using FFTA, Test
22

33
@testset "backward. N=$N" for N in [8, 11, 15, 16, 27, 100]
4-
x = ones(Float64, N, N)
4+
x = ones(Complex{Float64}, N, N)
55
y = brfft(x, 2(N-1))
66
y_ref = 0*y
77
y_ref[1] = N*(2(N-1))
@@ -14,12 +14,12 @@ end
1414
# Assuming that rfft works since it is tested independently
1515
Y = rfft(X)
1616

17-
@testset "round trip" begin
17+
@testset "round trip with irfft" begin
1818
@test X irfft(Y, m)
1919
end
2020

2121
@testset "allocations" begin
22-
@test (@test_allocations bfft(X)) <= 12050
22+
@test (@test_allocations brfft(Y, m)) <= 12050
2323
end
2424
end
2525
end

0 commit comments

Comments
 (0)