Fiddle with Monte. Callbacks are being stored but not called
[Math-GSL.git] / t / Monte.t
blob1d328b424c992ae6926821c8d9cf6ccf4bce5535
1 package Math::GSL::Monte::Test;
2 use base q{Test::Class};
3 use Test::More tests => 12;
4 use Math::GSL::Monte qw/:all/;
5 use Math::GSL::Errno qw/:all/;
6 use Math::GSL::RNG   qw/:all/;
7 use Math::GSL::Test  qw/:all/;
8 use Data::Dumper;
9 use strict;
11 BEGIN { gsl_set_error_handler_off() }
13 sub make_fixture : Test(setup) {
14     my $self = shift;
15     my $j          = 1 + int(rand(20));
16     $self->{miser} = gsl_monte_miser_alloc($j);
17     $self->{vegas} = gsl_monte_vegas_alloc($j);
18     $self->{plain} = gsl_monte_plain_alloc($j);
19     $self->{dim}   = $j;
22 sub teardown : Test(teardown) {
23     my $self = shift;
24     gsl_monte_miser_free($self->{miser});
25     gsl_monte_plain_free($self->{plain});
26     gsl_monte_vegas_free($self->{vegas});
29 sub TEST_INIT  : Tests(3) {
30     my $self = shift;
31     ok_status( gsl_monte_plain_init($self->{plain}), $GSL_SUCCESS, 'plain' );
32     ok_status( gsl_monte_vegas_init($self->{vegas}), $GSL_SUCCESS, 'vegas' );
33     ok_status( gsl_monte_miser_init($self->{miser}), $GSL_SUCCESS, 'miser' );
36 sub TEST_MONTE_VEGAS_INTEGRATE : Tests(3) {
37     my $self = shift;
38     my $state = gsl_monte_vegas_alloc(1);
39     my $rng   = Math::GSL::RNG->new;
40     my $status;
41     eval {
42           $status =  gsl_monte_vegas_integrate( sub { $_[0] ** 2 },
43         [ 0 ], [ 1 ], 1, 500000, $rng->raw, $state,);
44     };
45     ok( $state->{dim} == 1, 'dim = 1');
46     local $TODO = 'gsl_monte_function is broke';
47     ok_similar( [ 1/3 ] ,  [ $state->{result} ] );
48     ok_status($status, $TODO);
51 sub TEST_ALLOC : Tests(6) {
52     my $self = shift;
53     isa_ok($self->{miser},'Math::GSL::Monte');
54     cmp_ok($self->{miser}->{dim},'==',$self->{dim});
56     isa_ok($self->{vegas},'Math::GSL::Monte');
57     cmp_ok($self->{vegas}->{dim},'==',$self->{dim});
59     isa_ok($self->{plain},'Math::GSL::Monte');
60     cmp_ok($self->{plain}->{dim},'==',$self->{dim});
62 Test::Class->runtests;