1 package Math::GSL::Combination::Test;
2 use base q{Test::Class};
3 use Test::More tests => 23;
4 use Math::GSL::Test qw/:all/;
5 use Math::GSL::Combination qw/:all/;
6 use Math::GSL::Errno qw/:all/;
7 use Math::GSL qw/:all/;
11 sub make_fixture : Test(setup) {
13 $self->{comb} = gsl_combination_calloc(10,5);
14 $self->{obj} = Math::GSL::Combination->new(10,5);
17 sub teardown : Test(teardown) {
19 unlink 'combo.txt' if -e 'combo.txt';
22 sub GSL_COMBINATION_ALLOC : Tests {
23 my $c = gsl_combination_alloc(2,2);
24 isa_ok($c, 'Math::GSL::Combination');
27 sub GSL_COMBINATION_CALLOC : Tests {
28 my $c = gsl_combination_calloc(2,2);
29 isa_ok($c, 'Math::GSL::Combination');
32 sub GSL_COMBINATION_GET : Tests {
34 map {ok(gsl_combination_get($self->{comb}, $_) eq $_) } (0..4);
37 sub GSL_COMBINATION_NEXT : Tests {
38 my $c = gsl_combination_calloc(6,3);
39 is_deeply( [ map{ gsl_combination_get($c,$_) } (0..1) ] , [ 0 .. 1 ] );
40 ok_status(gsl_combination_next($c));
41 is_deeply( [ map{ gsl_combination_get($c,$_) } (0..2) ] , [ 0, 1, 3 ] );
45 my $c = Math::GSL::Combination->new(5,5);
46 isa_ok($c, 'Math::GSL::Combination');
47 is_deeply( [ map { gsl_combination_get($c->raw, $_) } (0..4) ],
53 is_deeply( [ $self->{obj}->as_list ] , [ 0 .. 4 ] );
58 ok($self->{obj}->length eq 10);
61 sub ELEMENTS : Tests {
63 ok($self->{obj}->elements eq 5);
66 sub NEXT_STATUS : Tests {
67 my $c = Math::GSL::Combination->new(6,3);
69 ok( $c->status() == 0 );
72 sub PREV_STATUS : Tests {
73 my $c = Math::GSL::Combination->new(6,3);
76 ok( $c->status() == 0 );
80 my $c = Math::GSL::Combination->new(6,3);
81 my $new = Math::GSL::Combination->new(6,3);
82 my $fd = gsl_fopen('combo.txt', 'w') or die $!;
83 ok_status( gsl_combination_fwrite($fd, $c->raw) );
85 $fd = gsl_fopen('combo.txt', 'r') or die $!;
86 ok_status(gsl_combination_fread($fd, $new->raw));
87 is_deeply ( [ $c->as_list ], [ $new->as_list ] );
91 my $c = Math::GSL::Combination->new(6,3);
93 is_deeply( [ $c->as_list ] , [ 0 .. 2 ] );
95 ok_status( $c->status );
96 is_deeply( [ $c->as_list ] , [ 0 , 1, 3 ] );
99 Test::Class->runtests;