1 package Math::GSL::FFT::Test;
2 use base q{Test::Class};
3 use Test::More tests => 16;
4 use Math::GSL::Test qw/:all/;
5 use Math::GSL::FFT qw/:all/;
6 use Math::GSL qw/:all/;
7 use Math::GSL::Errno qw/:all/;
11 BEGIN { gsl_set_error_handler_off() }
13 sub make_fixture : Test(setup) {
16 sub teardown : Test(teardown) {
17 unlink 'fft' if -f 'fft';
20 sub FFT_REAL_RADIX2_TRANSFORM : Tests(2)
22 my $input = [ (0) x 5, (1) x 22, (0) x 5 ];
23 my $expected = [ 22, -8.44205264582682, -4.64465605976076, -0.643126602526688, 1.70710678118655, 1.8349201998544,
24 0.572726230154202, -0.676964287646119, -1, -0.455944707054924, 0.255700894591988, 0.524240654352147,
25 0.292893218813453, -0.059180002187481, -0.183771064985432, -0.0818926089645147, 0, -0.831469612302545,
26 -0.923879532511287, -0.195090322016128, 0.707106781186547, 0.98078528040323, 0.38268343236509,
27 -0.555570233019602, -1, -0.555570233019602, 0.38268343236509, 0.980785280403231, 0.707106781186547,
28 -0.195090322016128, -0.923879532511287, -0.831469612302545
30 my ($status, $output ) = gsl_fft_real_radix2_transform ($input, 1, 32);
33 local $TODO = q{ not working again };
34 ok_similar( $output, $expected );
37 sub FFT_COMPLEX_RADIX2_FORWARD : Tests(2)
39 my $data = [ (1) x 10, (0) x 236, (1) x 10 ];
40 my ($status, $fft) = gsl_fft_complex_radix2_forward ($data, 1, 128);
42 local $TODO = 'fft of complex_packed_array does not work';
43 # we should propably use the gsl_fft_real_unpack function here to create a suitable complex_packed_array
47 sub FFT_VARS : Tests(2) {
48 cmp_ok( $gsl_fft_forward, '==', -1, 'gsl_fft_forward' );
49 cmp_ok( $gsl_fft_backward, '==', +1, 'gsl_fft_backward' );
52 sub WAVETABLE_ALLOC_FREE: Tests(6) {
53 my $wavetable = gsl_fft_complex_wavetable_alloc(42);
54 isa_ok($wavetable, 'Math::GSL::FFT' );
55 gsl_fft_complex_wavetable_free($wavetable);
56 ok(!$@, 'gsl_fft_complex_wavetable_free');
58 $wavetable = gsl_fft_halfcomplex_wavetable_alloc(42);
59 isa_ok($wavetable, 'Math::GSL::FFT' );
60 gsl_fft_halfcomplex_wavetable_free($wavetable);
61 ok(!$@, 'gsl_fft_halfcomplex_wavetable_free');
63 $wavetable = gsl_fft_real_wavetable_alloc(42);
64 isa_ok($wavetable, 'Math::GSL::FFT' );
65 gsl_fft_real_wavetable_free($wavetable);
66 ok(!$@, 'gsl_fft_real_wavetable_free');
70 sub WORKSPACE_ALLOC_FREE: Tests(4) {
71 my $workspace = gsl_fft_complex_workspace_alloc(42);
72 isa_ok($workspace, 'Math::GSL::FFT' );
73 gsl_fft_complex_workspace_free($workspace);
74 ok(!$@, 'gsl_fft_complex_workspace_free');
76 # there are no gsl_fft_halfcomplex_workspace_* functions
78 $workspace = gsl_fft_real_workspace_alloc(42);
79 isa_ok($workspace, 'Math::GSL::FFT' );
80 gsl_fft_real_workspace_free($workspace);
81 ok(!$@, 'gsl_fft_real_workspace_free');
83 Test::Class->runtests;