1 package Math::GSL::Deriv::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::Deriv qw/:all/;
7 use Math::GSL::Errno qw/:all/;
13 BEGIN{ gsl_set_error_handler_off() };
15 sub make_fixture : Test(setup) {
17 $self->{gsl_func} = Math::GSL::Deriv::gsl_function_struct->new;
20 sub teardown : Test(teardown) {
23 sub TEST_FUNCTION_STRUCT : Tests {
26 isa_ok( $self->{gsl_func},'Math::GSL::Deriv::gsl_function_struct');
29 sub TEST_DERIV_CENTRAL_DIES : Tests {
32 gsl_deriv_central( 'IAMNOTACODEREF', $x, $h);
33 },qr/not a reference value/, 'gsl_deriv_central borks when first arg is not a coderef');
36 sub TEST_DERIV_CENTRAL : Tests {
39 my ($status, $result);
41 ($status, $result) = gsl_deriv_central ( sub { $_[0] ** 3 }, $x, $h,);
43 my $res = abs($result->[0]-3*$x**2);
44 ok( $res < $result->[1] , sprintf ("gsl_deriv_forward: res=%.18f, abserr=%.18f",$res, $result->[1] ));
47 sub TEST_DERIV_FORWARD : Tests {
50 my ($status, $result);
52 ($status, $result) = gsl_deriv_forward ( sub { 2 * $_[0] ** 2 }, $x, $h,);
54 my $res = abs($result->[0]-4*$x);
55 ok( $res < $result->[1] , sprintf ("gsl_deriv_forward: res=%.18f, abserr=%.18f",$res, $result->[1] ));
58 sub TEST_DERIV_BACKWARD : Tests {
61 my ($status, $result);
63 ($status, $result) = gsl_deriv_backward ( sub { log $_[0] }, $x, $h,);
65 my $res = abs($result->[0]-1/$x);
66 ok( $res < $result->[1] , sprintf ("gsl_deriv_backward: res=%.18f, abserr=%.18f",$res, $result->[1] ));
69 sub TEST_DERIV_CENTRAL_CALLS_THE_SUB : Tests {
74 gsl_deriv_central ( sub { die "CALL ME BACK!"} , $x, $h)
75 }, qr/CALL ME BACK/, 'gsl_deriv_central can call anon sub' );
77 Test::Class->runtests;