1 package Math::GSL::Sum::Test;
2 use Math::GSL::Test qw/:all/;
3 use base q{Test::Class};
5 use Math::GSL::Errno qw/:all/;
6 use Math::GSL::Const qw/:all/;
7 use Math::GSL::Machine qw/:all/;
8 use Math::GSL::Sum qw/:all/;
9 use Math::GSL qw/:all/;
14 sub make_fixture : Test(setup) {
17 sub teardown : Test(teardown) {
20 sub LEVIN_U_ALLOC_FREE : Tests {
21 my $w = gsl_sum_levin_u_alloc(5);
22 isa_ok($w, 'Math::GSL::Sum');
23 gsl_sum_levin_u_free($w);
24 ok(!$@, 'gsl_histogram_free');
27 sub LEVIN_UTRUNC_ALLOC_FREE : Tests {
28 my $w = gsl_sum_levin_utrunc_alloc(5);
29 isa_ok($w, 'Math::GSL::Sum');
30 gsl_sum_levin_utrunc_free($w);
31 ok(!$@, 'gsl_histogram_free');
38 my $zeta_2 = $M_PI * $M_PI / 6.0;
43 $t->[$n] = 1.0 / ($np1 * $np1);
46 my $w = gsl_sum_levin_utrunc_alloc (50);
48 my @got = gsl_sum_levin_utrunc_accel ($t, 50, $w);
49 ok_status($got[0], $GSL_SUCCESS);
50 ok(is_similar_relative($got[1], $zeta_2, 1e-8), "trunc result, zeta(2)");
52 # No need to check precision for truncated result since this is not a meaningful number
54 gsl_sum_levin_utrunc_free ($w);
57 $w = gsl_sum_levin_u_alloc (50);
59 @got = gsl_sum_levin_u_accel ($t, 50, $w);
60 ok_status($got[0], $GSL_SUCCESS);
61 ok(is_similar_relative($got[1], $zeta_2, 1e-8), "full result, zeta(2)");
63 my $sd_est = -(log($got[2]/abs($got[1]))/log(10));
64 my $sd_actual = -(log($GSL_DBL_EPSILON + abs(($got[1] - $zeta_2)/$zeta_2))/log(10));
66 # Allow one digit of slop
68 local $TODO = "The error test from GSL fails here";
69 ok ($sd_est > $sd_actual + 1.0, "full significant digits, zeta(2) ($sd_est vs $sd_actual)");
71 gsl_sum_levin_u_free ($w);
82 $t->[$n] = $t->[$n - 1] * ($x / $n);
84 my $w = gsl_sum_levin_utrunc_alloc (50);
86 my @got = gsl_sum_levin_utrunc_accel ($t, 50, $w);
87 ok_status($got[0], $GSL_SUCCESS);
88 ok(is_similar_relative($got[1], $y, 1e-8), "trunc result, exp(10)");
90 # No need to check precision for truncated result since this is not a meaningful number
92 gsl_sum_levin_utrunc_free ($w);
95 $w = gsl_sum_levin_u_alloc (50);
97 @got = gsl_sum_levin_u_accel ($t, 50, $w);
98 ok_status($got[0], $GSL_SUCCESS);
99 ok(is_similar_relative($got[1], $y, 1e-8), "full result, exp(10)");
101 my $sd_est = -(log($got[2]/abs($got[1]))/log(10));
102 my $sd_actual = -(log($GSL_DBL_EPSILON + abs(($got[1] - $y)/$y))/log(10));
104 # Allow one digit of slop
105 local $TODO = "The error test from GSL fails here";
106 ok ($sd_est > $sd_actual + 1.0, "full significant digits, exp(10) ($sd_est vs $sd_actual)");
108 gsl_sum_levin_u_free ($w);
111 Test::Class->runtests;