Skip to content

Commit 8f1f4e4

Browse files
authored
Merge pull request #26 from zoziha/testdrive
Use testdrive for unit tests
2 parents 18886cd + 2edada5 commit 8f1f4e4

18 files changed

+428
-562
lines changed

fpm.toml

+6-70
Original file line numberDiff line numberDiff line change
@@ -13,82 +13,18 @@ keywords = ["netlib", "fftpack", "fft"]
1313
[build]
1414
auto-executables = false
1515
auto-tests = false
16-
auto-examples = true
16+
auto-examples = false
17+
18+
[dev-dependencies]
19+
test-drive = { git = "https://github.com/fortran-lang/test-drive", tag = "v0.4.0" }
1720

1821
# Original test
1922
[[test]]
2023
name = "tstfft"
2124
source-dir = "test"
2225
main = "tstfft.f"
2326

24-
# `fftpack` fft routines
25-
[[test]]
26-
name = "fftpack_zfft"
27-
source-dir = "test"
28-
main = "test_fftpack_zfft.f90"
29-
30-
[[test]]
31-
name = "fftpack_fft"
32-
source-dir = "test"
33-
main = "test_fftpack_fft.f90"
34-
35-
[[test]]
36-
name = "fftpack_ifft"
37-
source-dir = "test"
38-
main = "test_fftpack_ifft.f90"
39-
40-
[[test]]
41-
name = "fftpack_dfft"
42-
source-dir = "test"
43-
main = "test_fftpack_dfft.f90"
44-
45-
[[test]]
46-
name = "fftpack_rfft"
47-
source-dir = "test"
48-
main = "test_fftpack_rfft.f90"
49-
50-
[[test]]
51-
name = "fftpack_irfft"
52-
source-dir = "test"
53-
main = "test_fftpack_irfft.f90"
54-
55-
[[test]]
56-
name = "fftpack_dzfft"
57-
source-dir = "test"
58-
main = "test_fftpack_dzfft.f90"
59-
60-
[[test]]
61-
name = "fftpack_dcosq"
62-
source-dir = "test"
63-
main = "test_fftpack_dcosq.f90"
64-
65-
[[test]]
66-
name = "fftpack_qct"
67-
source-dir = "test"
68-
main = "test_fftpack_qct.f90"
69-
70-
[[test]]
71-
name = "fftpack_iqct"
72-
source-dir = "test"
73-
main = "test_fftpack_iqct.f90"
74-
75-
[[test]]
76-
name = "fftpack_dcost"
77-
source-dir = "test"
78-
main = "test_fftpack_dcost.f90"
79-
80-
[[test]]
81-
name = "fftpack_dct"
82-
source-dir = "test"
83-
main = "test_fftpack_dct.f90"
84-
85-
# `fftpack` utility routines
86-
[[test]]
87-
name = "fftpack_fftshift"
88-
source-dir = "test"
89-
main = "test_fftpack_fftshift.f90"
90-
9127
[[test]]
92-
name = "fftpack_ifftshift"
28+
name = "test_fftpack"
9329
source-dir = "test"
94-
main = "test_fftpack_ifftshift.f90"
30+
main = "test_fftpack.f90"

test/Makefile

+41-61
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,51 @@
1+
FETCH = curl -L
2+
3+
SRC = \
4+
test_fftpack_fft.f90 \
5+
test_fftpack_rfft.f90 \
6+
test_fftpack_qct.f90 \
7+
test_fftpack_dct.f90 \
8+
test_fftpack_utils.f90 \
9+
test_fftpack.f90 \
10+
testdrive.F90
11+
12+
OBJ = $(SRC:.f90=.o)
13+
OBJ := $(OBJ:.F90=.o)
14+
115
all: tstfft \
2-
fftpack_fft \
3-
fftpack_ifft \
4-
fftpack_rfft \
5-
fftpack_irfft \
6-
fftpack_fftshift \
7-
fftpack_ifftshift \
8-
fftpack_dzfft \
9-
fftpack_dcosq \
10-
fftpack_qct \
11-
fftpack_iqct \
12-
fftpack_dcost \
13-
fftpack_dct
16+
test_fftpack
1417

1518
# Orginal test
1619
tstfft: tstfft.f
1720
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
1821
time ./tstfft.x
1922

2023
# `fftpack` fft routines
21-
fftpack_fft: test_fftpack_fft.f90
22-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
23-
./fftpack_fft.x
24-
25-
fftpack_ifft: test_fftpack_ifft.f90
26-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
27-
./fftpack_ifft.x
28-
29-
fftpack_rfft: test_fftpack_rfft.f90
30-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
31-
./fftpack_rfft.x
32-
33-
fftpack_irfft: test_fftpack_irfft.f90
34-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
35-
./fftpack_irfft.x
36-
37-
fftpack_dzfft: test_fftpack_dzfft.f90
38-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
39-
./fftpack_dzfft.x
40-
41-
fftpack_dcosq: test_fftpack_dcosq.f90
42-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
43-
./fftpack_dcosq.x
44-
45-
fftpack_qct: test_fftpack_qct.f90
46-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
47-
./fftpack_qct.x
48-
49-
fftpack_iqct: test_fftpack_iqct.f90
50-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
51-
./fftpack_iqct.x
52-
53-
fftpack_dcost: test_fftpack_dcost.f90
54-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
55-
./fftpack_dcost.x
56-
57-
fftpack_dct: test_fftpack_dct.f90
58-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
59-
./fftpack_dct.x
60-
61-
# `fftpack` utility routines
62-
fftpack_fftshift: test_fftpack_fftshift.f90
63-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
64-
./fftpack_fftshift.x
65-
66-
fftpack_ifftshift: test_fftpack_ifftshift.f90
67-
$(FC) $(FFLAGS) $< -L../src -l$(LIB) -I../src -o $@.x
68-
./fftpack_ifftshift.x
24+
test_fftpack: $(OBJ)
25+
$(FC) $(FFLAGS) $(OBJ) -L../src -l$(LIB) -I../src -o $@.x
26+
./test_fftpack.x
27+
28+
testdrive.F90:
29+
$(FETCH) https://github.com/fortran-lang/test-drive/raw/v0.4.0/src/testdrive.F90 > $@
30+
31+
%.o: %.F90
32+
$(FC) $(FFLAGS) -c $<
33+
34+
%.o: %.f90
35+
$(FC) $(FFLAGS) -I../src -c $<
36+
37+
test_fftpack.o: test_fftpack_fft.o \
38+
test_fftpack_rfft.o \
39+
test_fftpack_qct.o \
40+
test_fftpack_dct.o \
41+
test_fftpack_utils.o \
42+
testdrive.o
43+
44+
test_fftpack_fft.o: testdrive.o
45+
test_fftpack_rfft.o: testdrive.o
46+
test_fftpack_qct.o: testdrive.o
47+
test_fftpack_dct.o: testdrive.o
48+
test_fftpack_utils.o: testdrive.o
6949

7050
clean:
71-
rm -f -r *.o *.x
51+
rm -f -r *.o *.mod *.smod *.x testdrive.F90

test/test_fftpack.f90

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
program test_fftpack
2+
use, intrinsic :: iso_fortran_env, only: error_unit
3+
use testdrive, only: run_testsuite, new_testsuite, testsuite_type
4+
use test_fftpack_fft, only: collect_fft
5+
use test_fftpack_rfft, only: collect_rfft
6+
use test_fftpack_qct, only: collect_qct
7+
use test_fftpack_dct, only: collect_dct
8+
use test_fftpack_utils, only: collect_utils
9+
implicit none
10+
integer :: stat, is
11+
type(testsuite_type), allocatable :: testsuites(:)
12+
character(len=*), parameter :: fmt = '("#", *(1x, a))'
13+
14+
stat = 0
15+
16+
testsuites = [ &
17+
new_testsuite("fft", collect_fft), &
18+
new_testsuite("rfft", collect_rfft), &
19+
new_testsuite("qct", collect_qct), &
20+
new_testsuite("dct", collect_dct), &
21+
new_testsuite("utils", collect_utils) &
22+
]
23+
24+
do is = 1, size(testsuites)
25+
write (error_unit, fmt) "Testing:", testsuites(is)%name
26+
call run_testsuite(testsuites(is)%collect, error_unit, stat)
27+
end do
28+
29+
if (stat > 0) then
30+
write (error_unit, '(i0, 1x, a)') stat, "test(s) failed!"
31+
error stop
32+
end if
33+
34+
end program test_fftpack

test/test_fftpack_dcosq.f90

-30
This file was deleted.

test/test_fftpack_dcost.f90

-30
This file was deleted.

test/test_fftpack_dct.f90

+55-28
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,70 @@
1-
program tester
1+
module test_fftpack_dct
22

3-
call test_fftpack_dct()
4-
call test_fftpack_idct()
5-
print *, "All tests in `test_fftpack_dct` passed."
3+
use fftpack, only: rk, dcosti, dcost, dct, idct
4+
use testdrive, only: new_unittest, unittest_type, error_type, check
5+
implicit none
6+
private
7+
8+
public :: collect_dct
69

710
contains
811

9-
subroutine check(condition, msg)
10-
logical, intent(in) :: condition
11-
character(*), intent(in) :: msg
12-
if (.not. condition) error stop msg
13-
end subroutine check
12+
!> Collect all exported unit tests
13+
subroutine collect_dct(testsuite)
14+
!> Collection of tests
15+
type(unittest_type), allocatable, intent(out) :: testsuite(:)
16+
17+
testsuite = [ &
18+
new_unittest("classic-dct-API", test_classic_dct), &
19+
new_unittest("modernized-dct-API", test_modernized_dct), &
20+
new_unittest("modernized-idct-API", test_modernized_idct) &
21+
]
22+
23+
end subroutine collect_dct
24+
25+
subroutine test_classic_dct(error)
26+
type(error_type), allocatable, intent(out) :: error
27+
real(kind=rk) :: w(3*4 + 15)
28+
real(kind=rk) :: x(4) = [1, 2, 3, 4]
29+
real(kind=rk) :: eps = 1.0e-10_rk
30+
31+
call dcosti(4, w)
32+
call dcost(4, x, w)
33+
call check(error, all(x == [real(kind=rk) :: 15, -4, 0, -1.0000000000000009_rk]), "`dcosti` failed.")
34+
if (allocated(error)) return
35+
36+
call dcost(4, x, w)
37+
call check(error, all(x/(2.0_rk*(4.0_rk - 1.0_rk)) == [real(kind=rk) :: 1, 2, 3, 4]), "`dcost` failed.")
1438

15-
subroutine test_fftpack_dct
16-
use fftpack, only: dct
17-
use fftpack_kind
39+
end subroutine test_classic_dct
1840

41+
subroutine test_modernized_dct(error)
42+
type(error_type), allocatable, intent(out) :: error
1943
real(kind=rk) :: x(3) = [9, -9, 3]
2044

21-
call check(all(dct(x, 2) == [real(kind=rk) :: 0, 18]), msg="`dct(x, 2)` failed.")
22-
call check(all(dct(x, 3) == dct(x)), msg="`dct(x, 3)` failed.")
23-
call check(all(dct(x, 4) == [real(kind=rk) :: -3, -3.0000000000000036_rk, 15, 33]), msg="`dct(x, 4)` failed.")
45+
call check(error, all(dct(x, 2) == [real(kind=rk) :: 0, 18]), "`dct(x, 2)` failed.")
46+
if (allocated(error)) return
47+
call check(error, all(dct(x, 3) == dct(x)), "`dct(x, 3)` failed.")
48+
if (allocated(error)) return
49+
call check(error, all(dct(x, 4) == [real(kind=rk) :: -3, -3.0000000000000036_rk, 15, 33]), "`dct(x, 4)` failed.")
2450

25-
end subroutine test_fftpack_dct
51+
end subroutine test_modernized_dct
2652

27-
subroutine test_fftpack_idct
28-
use fftpack, only: dct, idct
29-
use iso_fortran_env, only: rk => real64
53+
subroutine test_modernized_idct(error)
54+
type(error_type), allocatable, intent(out) :: error
3055
real(kind=rk) :: eps = 1.0e-10_rk
3156
real(kind=rk) :: x(4) = [1, 2, 3, 4]
3257

33-
call check(all(idct(dct(x))/(2.0_rk*(4.0_rk - 1.0_rk)) == [real(kind=rk) :: 1, 2, 3, 4]), &
34-
msg="`idct(dct(x))/(2.0_rk*(4.0_rk-1.0_rk))` failed.")
35-
call check(all(idct(dct(x), 2)/(2.0_rk*(2.0_rk - 1.0_rk)) == [real(kind=rk) :: 5.5, 9.5]), &
36-
msg="`idct(dct(x), 2)/(2.0_rk*(2.0_rk-1.0_rk))` failed.")
37-
call check(all(idct(dct(x, 2), 4)/(2.0_rk*(4.0_rk - 1.0_rk)) == &
38-
[0.16666666666666666_rk, 0.33333333333333331_rk, 0.66666666666666663_rk, 0.83333333333333315_rk]), &
39-
msg="`idct(dct(x, 2), 4)/(2.0_rk*(4.0_rk-1.0_rk))` failed.")
58+
call check(error, all(idct(dct(x))/(2.0_rk*(4.0_rk - 1.0_rk)) == [real(kind=rk) :: 1, 2, 3, 4]), &
59+
"`idct(dct(x))/(2.0_rk*(4.0_rk-1.0_rk))` failed.")
60+
if (allocated(error)) return
61+
call check(error, all(idct(dct(x), 2)/(2.0_rk*(2.0_rk - 1.0_rk)) == [real(kind=rk) :: 5.5, 9.5]), &
62+
"`idct(dct(x), 2)/(2.0_rk*(2.0_rk-1.0_rk))` failed.")
63+
if (allocated(error)) return
64+
call check(error, all(idct(dct(x, 2), 4)/(2.0_rk*(4.0_rk - 1.0_rk)) == &
65+
[0.16666666666666666_rk, 0.33333333333333331_rk, 0.66666666666666663_rk, 0.83333333333333315_rk]), &
66+
"`idct(dct(x, 2), 4)/(2.0_rk*(4.0_rk-1.0_rk))` failed.")
4067

41-
end subroutine test_fftpack_idct
68+
end subroutine test_modernized_idct
4269

43-
end program tester
70+
end module test_fftpack_dct

0 commit comments

Comments
 (0)