Refactor inclusion of system.i to one place
[Math-GSL.git] / t / Combination.t
blob93632ec6963da17f05f8083f7d93d2684f21c394
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/;
8 use Data::Dumper;
9 use strict;
11 sub make_fixture : Test(setup) {
12     my $self = shift;
13     $self->{comb} = gsl_combination_calloc(10,5);
14     $self->{obj} = Math::GSL::Combination->new(10,5);
17 sub teardown : Test(teardown) {
18     my $self = shift;
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 {
33     my $self = shift; 
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 ] );
42
44 sub NEW : Tests { 
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) ],
48         [ 0 .. 4 ] );   
51 sub AS_LIST: Tests { 
52     my $self = shift;
53     is_deeply( [ $self->{obj}->as_list ] , [ 0 .. 4 ] );
56 sub LENGTH : Tests {
57     my $self = shift;
58     ok($self->{obj}->length eq 10);
61 sub ELEMENTS : Tests {
62     my $self = shift;
63     ok($self->{obj}->elements eq 5);
66 sub NEXT_STATUS : Tests {
67     my $c = Math::GSL::Combination->new(6,3);
68     $c->next();
69     ok( $c->status() == 0 );    
72 sub PREV_STATUS : Tests {
73     my $c = Math::GSL::Combination->new(6,3);
74     $c->next();
75     $c->prev();
76     ok( $c->status() == 0 );    
79 sub FWRITE : Tests {
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) );
84     gsl_fclose($fd);
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 ] );
90 sub NEXT : Tests {
91     my $c = Math::GSL::Combination->new(6,3);
92     
93     is_deeply( [ $c->as_list ] , [ 0 .. 2 ] );
94     $c->next;
95     ok_status( $c->status );
96     is_deeply( [ $c->as_list ] , [ 0 , 1, 3 ] );
99 Test::Class->runtests;