Make callbacks work for gsl_deriv_central. Yay!
[Math-GSL.git] / t / Deriv.t
blobe9f74960a1068186d0815394a47b97ef0465ee27
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/;
8 use Test::Exception;
9 use Data::Dumper;
10 use strict;
11 use warnings;
13 BEGIN{ gsl_set_error_handler_off() };
15 sub make_fixture : Test(setup) {
16     my $self = shift;
17     $self->{gsl_func} = Math::GSL::Deriv::gsl_function_struct->new;
20 sub teardown : Test(teardown) {
23 sub TEST_FUNCTION_STRUCT : Tests {
24     my $self = shift;
26     isa_ok( $self->{gsl_func},'Math::GSL::Deriv::gsl_function_struct');
29 sub TEST_DERIV_CENTRAL_DIES : Tests { 
30     my ($x,$h)=(10,0.01);
31     throws_ok( sub {
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 AAA_TEST_DERIV_CENTRAL : Tests { 
37     my ($status, $result, $abserr);
38     my ($x,$h)=(10,0.01);
39     my $self = shift;
40     my @other;
43     ($status, $result) = gsl_deriv_central ( 
44                             sub { $_[0] ** 3 },
45                             $x, $h,
46     ); 
47     ok_status($status);
48     ok_similar( [$result->[0]], [3*$x**2], 'gsl_deriv_central returns correct value for anon sub' );
51 sub TEST_DERIV_CENTRAL_CALLS_THE_SUB : Tests { 
52     my ($status, $result, $abserr);
53     my ($x,$h)=(10,0.01);
54     my $self = shift;
56     throws_ok( sub {
57                 gsl_deriv_central ( sub { die "CALL ME BACK!"} , $x, $h)
58             }, qr/CALL ME BACK/, 'gsl_deriv_central can call anon sub' );
60 Test::Class->runtests;