Refactor inclusion of system.i to one place
[Math-GSL.git] / t / Monte.t
blob7b3b220fcb5f53060040a9747f18eaa8dd3b73ab
1 package Math::GSL::Monte::Test;
2 use base q{Test::Class};
3 use Test::More tests => 10;
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 strict;
10 BEGIN { gsl_set_error_handler_off() }
12 sub make_fixture : Test(setup) {
13     my $self = shift;
14     my $j          = 1 + int(rand(20));
15     $self->{miser} = gsl_monte_miser_alloc($j);
16     $self->{vegas} = gsl_monte_vegas_alloc($j);
17     $self->{plain} = gsl_monte_plain_alloc($j);
18     $self->{dim}   = $j;
21 sub teardown : Test(teardown) {
22     my $self = shift;
23     gsl_monte_miser_free($self->{miser});
24     gsl_monte_plain_free($self->{plain});
25     gsl_monte_vegas_free($self->{vegas});
28 sub TEST_INIT  : Tests {
29     my $self = shift;
30     ok_status( gsl_monte_plain_init($self->{plain}) );
31     ok_status( gsl_monte_vegas_init($self->{vegas}) );
32     ok_status( gsl_monte_miser_init($self->{miser}) );
35 sub TEST_MONTE_VEGAS_INTEGRATE : Tests {
36     my $self = shift;
37     my $state = gsl_monte_vegas_alloc(1);
38     my $rng   = Math::GSL::RNG->new;
39     my $result = [];
40     my $err = [];
41     local $TODO = 'gsl_monte_function is broke';
42     my $status;
43     eval {
44           $status =  gsl_monte_vegas_integrate( sub { $_[0] ** 2 },
45         [ 0 ], [ 1 ], 1, 500_000, $rng->raw, $state, $result, $err)
46     };
47     ok_status($status);
50 sub TEST_ALLOC : Tests {
51     my $self = shift;
52     isa_ok($self->{miser},'Math::GSL::Monte');
53     cmp_ok($self->{miser}->{dim},'==',$self->{dim});
55     isa_ok($self->{vegas},'Math::GSL::Monte');
56     cmp_ok($self->{vegas}->{dim},'==',$self->{dim});
58     isa_ok($self->{plain},'Math::GSL::Monte');
59     cmp_ok($self->{plain}->{dim},'==',$self->{dim});
61 Test::Class->runtests;