FFT typemap and test
[Math-GSL.git] / t / FFT.t
blob4e46898910f027cd4e4fb20a0f7149292cb53dca
1 package Math::GSL::FFT::Test;
2 use Math::GSL::Test qw/:all/;
3 use base q{Test::Class};
4 use Test::More;
5 use Math::GSL::FFT qw/:all/;
6 use Math::GSL qw/:all/;
7 use Data::Dumper;
8 use Math::GSL::Errno qw/:all/;
9 use strict;
11 BEGIN { gsl_set_error_handler_off() }
13 sub make_fixture : Test(setup) {
16 sub teardown : Test(teardown) {
17     unlink 'fft' if -f 'fft';
19 sub FFT_REAL_RADIX2_TRANSFORM : Tests 
21     my $data = [ (0) x 5, (1) x 22, (0) x 5 ];
22     my ($status1, $pass1 ) = gsl_fft_real_radix2_transform ($data, 1, 32);
23     ok_status($status1);
24     ok_similar( $pass1, [
25             22,
26             -8.44205264582682,
27             -4.64465605976076,
28             -0.643126602526688,
29             1.70710678118655,
30             1.8349201998544,
31             0.572726230154202,
32             -0.676964287646119,
33             -1,
34             -0.455944707054924,
35             0.255700894591988,
36             0.524240654352147,
37             0.292893218813453,
38             -0.059180002187481,
39             -0.183771064985432,
40             -0.0818926089645147,
41             0,
42             -0.831469612302545,
43             -0.923879532511287,
44             -0.195090322016128,
45             0.707106781186547,
46             0.98078528040323,
47             0.38268343236509,
48             -0.555570233019602,
49             -1,
50             -0.555570233019602,
51             0.38268343236509,
52             0.980785280403231,
53             0.707106781186547,
54             -0.195090322016128,
55             -0.923879532511287,
56             -0.831469612302545
57             ]);
60 sub FFT_COMPLEX_RADIX2_FORWARD : Tests 
62     my $data = [ (1) x 10, (0) x 236, (1) x 10 ];
63     ok_status( gsl_fft_complex_radix2_forward ($data, 1, 128) );
65 sub FFT_VARS : Tests {
66     cmp_ok( $gsl_fft_forward, '==', -1, 'gsl_fft_forward' );
67     cmp_ok( $gsl_fft_backward, '==', +1, 'gsl_fft_backward' );
70 sub WAVETABLE_ALLOC_FREE: Tests {
71     my $wavetable = gsl_fft_complex_wavetable_alloc(42);
72     isa_ok($wavetable, 'Math::GSL::FFT' );
73     gsl_fft_complex_wavetable_free($wavetable);
74     ok(!$@, 'gsl_fft_complex_wavetable_free');
76     $wavetable = gsl_fft_halfcomplex_wavetable_alloc(42);
77     isa_ok($wavetable, 'Math::GSL::FFT' );
78     gsl_fft_halfcomplex_wavetable_free($wavetable);
79     ok(!$@, 'gsl_fft_halfcomplex_wavetable_free');
81     $wavetable = gsl_fft_real_wavetable_alloc(42);
82     isa_ok($wavetable, 'Math::GSL::FFT' );
83     gsl_fft_real_wavetable_free($wavetable);
84     ok(!$@, 'gsl_fft_real_wavetable_free');
88 sub WORKSPACE_ALLOC_FREE: Tests {
89     my $workspace = gsl_fft_complex_workspace_alloc(42);
90     isa_ok($workspace, 'Math::GSL::FFT' );
91     gsl_fft_complex_workspace_free($workspace);
92     ok(!$@, 'gsl_fft_complex_workspace_free');
94     # there are no gsl_fft_halfcomplex_workspace_* functions
96     $workspace = gsl_fft_real_workspace_alloc(42);
97     isa_ok($workspace, 'Math::GSL::FFT' );
98     gsl_fft_real_workspace_free($workspace);
99     ok(!$@, 'gsl_fft_real_workspace_free');
101 Test::Class->runtests;