1 package Math::GSL::Statistics::Test;
2 use Math::GSL::Test qw/:all/;
3 use base q{Test::Class};
5 use Math::GSL::Statistics qw/:all/;
6 use Math::GSL::Sort qw/:all/;
7 use Math::GSL qw/:all/;
10 sub make_fixture : Test(setup) {
24 sub teardown : Test(teardown) {
27 sub GSL_STATS_MEAN : Tests {
28 my $x = gsl_stats_mean([2,3,4, 5], 1, 4);
32 sub GSL_STATS_VARIANCE : Tests {
33 my $x = gsl_stats_variance([2,3,4, 5], 1, 4);
37 sub GSL_STATS_SD : Tests {
39 my $x = gsl_stats_sd($self->{data}, 1, 20);
40 ok($x eq 3.79750610685209);
43 sub GSL_STATS_ABSDEV : Tests {
45 my $x = gsl_stats_absdev($self->{data},1, 20);
49 sub GSL_STATS_SKEW : Tests {
51 my $x = gsl_stats_skew($self->{data}, 1, 20);
52 ok($x eq -0.909355923168064);
55 sub GSL_STATS_KURTOSIS : Tests {
57 my $x = gsl_stats_kurtosis($self->{data}, 1, 20);
58 ok(is_similar_relative($x, -0.233692524908094));
61 sub GSL_STATS_COVARIANCE : Tests {
63 my $x = gsl_stats_covariance($self->{data}, 1, $self->{datab}, 1, 20);
64 ok(is_similar_relative($x, 14.5263157894737));
67 sub GSL_STATS_CORRELATION : Tests {
69 my $x = gsl_stats_correlation($self->{data}, 1, $self->{datab}, 1, 20);
70 ok(is_similar_relative($x, 0.793090350710101));
73 sub GSL_STATS_PVARIANCE : Tests {
75 my $x = gsl_stats_pvariance($self->{data}, 1, 20, $self->{datab}, 1, 20);
76 ok(is_similar_relative($x, 18.8421052631579));
79 sub GSL_STATS_TTEST : Tests {
81 my $x = gsl_stats_ttest($self->{data}, 1, 20, $self->{datab}, 1, 20);
82 ok(is_similar_relative($x, -1.45701922702927));
85 sub GSL_STATS_MAX : Tests {
87 my $x = gsl_stats_max($self->{data}, 1, 20);
88 ok(is_similar_relative($x, 22));
91 sub GSL_STATS_MIN : Tests {
93 my $x = gsl_stats_min($self->{data}, 1, 20);
94 ok(is_similar_relative($x, 8));
97 sub GSL_STATS_MINMAX : Tests {
99 my ($min, $max) = gsl_stats_minmax($self->{data}, 1, 20);
100 ok(is_similar_relative($max, 22));
101 ok(is_similar_relative($min, 8));
104 sub GSL_STATS_MAX_INDEX : Tests {
106 my $x = gsl_stats_max_index($self->{data}, 1, 20);
107 ok(is_similar_relative($x, 9));
110 sub GSL_STATS_MIN_INDEX : Tests {
112 my $x = gsl_stats_min_index($self->{data}, 1, 20);
113 ok(is_similar_relative($x, 12));
116 sub GSL_STATS_MINMAX_INDEX : Tests {
118 my ($min, $max) = gsl_stats_minmax_index($self->{data}, 1, 20);
119 ok(is_similar_relative($min, 12));
120 ok(is_similar_relative($max, 9));
123 sub GSL_STATS_MEDIAN_FROM_SORTED_DATA_EVEN : Tests {
125 my $sorted = gsl_sort($self->{data}, 1, 20);
126 my $x = gsl_stats_median_from_sorted_data($sorted, 1, 20);
127 ok(is_similar_relative($x, 18));
130 sub GSL_STATS_MEDIAN_FROM_SORTED_DATA_ODD : Tests {
132 my $sorted = gsl_sort($self->{data}, 1, 20);
133 my $x = gsl_stats_median_from_sorted_data($sorted, 1, 19);
134 ok(is_similar_relative($x, 18));
137 sub GSL_STATS_QUANTILE_FROM_SORTED_DATA_0 : Tests {
139 my $sorted = gsl_sort($self->{data}, 1, 20);
140 my $x = gsl_stats_quantile_from_sorted_data($sorted, 1, 20, 0);
141 ok(is_similar_relative($x, 8));
144 sub GSL_STATS_QUANTILE_FROM_SORTED_DATA_100 : Tests {
146 my $sorted = gsl_sort($self->{data}, 1, 20);
147 my $x = gsl_stats_quantile_from_sorted_data($sorted, 1, 20, 1);
148 ok(is_similar_relative($x, 22));
151 sub GSL_STATS_QUANTILE_FROM_SORTED_DATA_50_EVEN : Tests {
153 my $sorted = gsl_sort($self->{data}, 1, 20);
154 my $x = gsl_stats_quantile_from_sorted_data($sorted, 1, 20, 0.5);
155 ok(is_similar_relative($x, 18));
158 sub GSL_STATS_QUANTILE_FROM_SORTED_DATA_50_ODD : Tests {
160 my $sorted = gsl_sort($self->{data}, 1, 20);
161 my $x = gsl_stats_quantile_from_sorted_data($sorted, 1, 20, 0.5);
162 ok(is_similar_relative($x, 18));
165 sub GSL_STATS_LAG1_AUTOCORRELATION : Tests {
169 $numacc3->[0] = 1000000.2 ;
170 for ($i = 1 ; $i < 1000 ; $i += 2)
172 $numacc3->[$i] = 1000000.1 ;
173 $numacc3->[$i+1] = 1000000.3 ; }
174 my $mean = gsl_stats_mean ($numacc3, 1, $nacc3);
175 my $sd = gsl_stats_sd ($numacc3, 1, $nacc3);
176 my $lag1 = gsl_stats_lag1_autocorrelation ($numacc3, 1, $nacc3);
178 my $expected_mean = 1000000.2;
179 my $expected_sd = 0.1;
180 my $expected_lag1 = -0.999;
182 ok(is_similar_relative($mean, $expected_mean));
183 ok(is_similar_relative($sd, $expected_sd));
184 ok(is_similar_relative($lag1, $expected_lag1));
186 Test::Class->runtests;