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/;
10 BEGIN { gsl_set_error_handler_off() }
12 sub make_fixture : Test(setup) {
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);
21 sub teardown : Test(teardown) {
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 {
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 {
37 my $state = gsl_monte_vegas_alloc(1);
38 my $rng = Math::GSL::RNG->new;
41 local $TODO = 'gsl_monte_function is broke';
44 $status = gsl_monte_vegas_integrate( sub { $_[0] ** 2 },
45 [ 0 ], [ 1 ], 1, 500_000, $rng->raw, $state, $result, $err)
50 sub TEST_ALLOC : Tests {
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;