1 package Math::GSL::Sum::Test;
2 use base q{Test::Class};
3 use Test::More tests => 14;
4 use Math::GSL::Sum qw/:all/;
5 use Math::GSL::Test qw/:all/;
6 use Math::GSL::Errno qw/:all/;
7 use Math::GSL::Const qw/:all/;
8 use Math::GSL::Machine qw/:all/;
13 sub make_fixture : Test(setup) {
16 sub teardown : Test(teardown) {
19 sub LEVIN_U_ALLOC_FREE : Tests {
20 my $w = gsl_sum_levin_u_alloc(5);
21 isa_ok($w, 'Math::GSL::Sum');
22 gsl_sum_levin_u_free($w);
23 ok(!$@, 'gsl_histogram_free');
26 sub LEVIN_UTRUNC_ALLOC_FREE : Tests {
27 my $w = gsl_sum_levin_utrunc_alloc(5);
28 isa_ok($w, 'Math::GSL::Sum');
29 gsl_sum_levin_utrunc_free($w);
30 ok(!$@, 'gsl_histogram_free');
37 my $zeta_2 = $M_PI * $M_PI / 6.0;
42 $t->[$n] = 1.0 / ($np1 * $np1);
45 my $w = gsl_sum_levin_utrunc_alloc (50);
47 my @got = gsl_sum_levin_utrunc_accel ($t, 50, $w);
48 ok_status($got[0], $GSL_SUCCESS);
49 ok(is_similar_relative($got[1], $zeta_2, 1e-8), "trunc result, zeta(2)");
51 # No need to check precision for truncated result since this is not a meaningful number
53 gsl_sum_levin_utrunc_free ($w);
56 $w = gsl_sum_levin_u_alloc (50);
58 @got = gsl_sum_levin_u_accel ($t, 50, $w);
59 ok_status($got[0], $GSL_SUCCESS);
60 ok(is_similar_relative($got[1], $zeta_2, 1e-8), "full result, zeta(2)");
62 my $sd_est = -(log($got[2]/abs($got[1]))/log(10));
63 my $sd_actual = -(log($GSL_DBL_EPSILON + abs(($got[1] - $zeta_2)/$zeta_2))/log(10));
65 # Allow one digit of slop
67 local $TODO = "The error test from GSL fails here";
68 ok ($sd_est > $sd_actual + 1.0, "full significant digits, zeta(2) ($sd_est vs $sd_actual)");
70 gsl_sum_levin_u_free ($w);
81 $t->[$n] = $t->[$n - 1] * ($x / $n);
83 my $w = gsl_sum_levin_utrunc_alloc (50);
85 my @got = gsl_sum_levin_utrunc_accel ($t, 50, $w);
86 ok_status($got[0], $GSL_SUCCESS);
87 ok(is_similar_relative($got[1], $y, 1e-8), "trunc result, exp(10)");
89 # No need to check precision for truncated result since this is not a meaningful number
91 gsl_sum_levin_utrunc_free ($w);
94 $w = gsl_sum_levin_u_alloc (50);
96 @got = gsl_sum_levin_u_accel ($t, 50, $w);
97 ok_status($got[0], $GSL_SUCCESS);
98 ok(is_similar_relative($got[1], $y, 1e-8), "full result, exp(10)");
100 my $sd_est = -(log($got[2]/abs($got[1]))/log(10));
101 my $sd_actual = -(log($GSL_DBL_EPSILON + abs(($got[1] - $y)/$y))/log(10));
103 # Allow one digit of slop
104 local $TODO = "The error test from GSL fails here";
105 ok ($sd_est > $sd_actual + 1.0, "full significant digits, exp(10) ($sd_est vs $sd_actual)");
107 gsl_sum_levin_u_free ($w);
110 Test::Class->runtests;