1 package Math
::GSL
::Spline
::Test
;
2 use Math
::GSL
::Test qw
/:all/;
3 use base
'Test::Class';
4 use Test
::More
'no_plan';
5 use Math
::GSL qw
/:all/;
6 use Math
::GSL
::Spline qw
/:all/;
7 use Math
::GSL
::Errno qw
/:all/;
8 use Math
::GSL
::Interp qw
/:all/;
14 BEGIN{ gsl_set_error_handler_off
() };
16 sub make_fixture
: Test
(setup
) {
18 $self->{spline
} = gsl_spline_alloc
($gsl_interp_linear,100);
21 sub teardown
: Test
(teardown
) {
23 sub TEST_FREE
: Test
{
25 gsl_spline_free
($self->{spline
});
26 ok
(!$@
&& !$! && !$?
,'gsl_spline_free');
28 sub TEST_MIN_SIZE
: Test
{
30 cmp_ok
(2,'==',gsl_spline_min_size
($self->{spline
}),'min_size');
32 sub TEST_NAME
: Test
{
34 my $spline = $self->{spline
};
35 cmp_ok
('linear', 'eq' , gsl_spline_name
($spline));
37 sub TEST_ALLOC
: Tests
{
38 isa_ok
(gsl_spline_alloc
($_,100), 'Math::GSL::Spline') for (
40 $gsl_interp_polynomial,
42 $gsl_interp_cspline_periodic,
44 $gsl_interp_akima_periodic);
47 sub MULTIPLE_TESTS
: Tests
{
48 my $a = gsl_interp_accel_alloc
();
49 my $spline = gsl_spline_alloc
($gsl_interp_polynomial, 4);
50 my $data_x = [ 0.0, 1.0, 2.0, 3.0 ];
51 my $data_y = [ 0.0, 1.0, 2.0, 3.0 ];
52 ok_status
(gsl_spline_init
($spline, $data_x, $data_y, 4), $GSL_SUCCESS);
53 my $test_x = [ 0.0, 0.5, 1.0, 1.5, 2.5, 3.0 ];
54 my $test_y = [ 0.0, 0.5, 1.0, 1.5, 2.5, 3.0 ];
55 my $test_dy = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ];
56 my $test_iy = [ 0.0, 0.125, 0.5, 9.0/8.0, 25.0/8.0, 9.0/2.0 ];
59 my $x = $test_x->[$i];
60 my ($s1, $y) = gsl_spline_eval_e
($spline,$x, $a);
61 my ($s2, $deriv) = gsl_spline_eval_deriv_e
($spline, $x, $a);
62 my ($s3, $integ) = gsl_spline_eval_integ_e
($spline, $test_x->[0], $x, $a);
68 ok_similar
([$y, $deriv, $integ], [$test_y->[$i], $test_dy->[$i], $test_iy->[$i]], "eval_e, derive_e and integ_e",1e-10);
70 my $diff_y = $y - $test_y->[$i];
71 my $diff_deriv = $deriv - $test_dy->[$i];
72 my $diff_integ = $integ - $test_iy->[$i];
73 ok
( abs($diff_y) < 1e-10, "diff_y");
74 ok
( abs($diff_deriv) < 1e-10, "diff_deriv");
75 ok
( abs($diff_integ) < 1e-10, "diff_integ");
77 gsl_interp_accel_free
($a);
78 gsl_spline_free
($spline);