Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 101 lines (84 sloc) 2.601 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
package Math::GSL::Combination::Test;
use base q{Test::Class};
use Test::More tests => 23;
use Math::GSL::Test qw/:all/;
use Math::GSL::Combination qw/:all/;
use Math::GSL::Errno qw/:all/;
use Math::GSL qw/:all/;
use Data::Dumper;
use strict;

BEGIN { gsl_set_error_handler_off() }

sub make_fixture : Test(setup) {
    my $self = shift;
    $self->{comb} = gsl_combination_calloc(10,5);
    $self->{obj} = Math::GSL::Combination->new(10,5);
}

sub teardown : Test(teardown) {
    my $self = shift;
    unlink 'combo.txt' if -e 'combo.txt';
}

sub GSL_COMBINATION_ALLOC : Tests {
    my $c = gsl_combination_alloc(2,2);
    isa_ok($c, 'Math::GSL::Combination');
}

sub GSL_COMBINATION_CALLOC : Tests {
    my $c = gsl_combination_calloc(2,2);
    isa_ok($c, 'Math::GSL::Combination');
}

sub GSL_COMBINATION_GET : Tests {
    my $self = shift;
    map {ok(gsl_combination_get($self->{comb}, $_) eq $_) } (0..4);
}

sub GSL_COMBINATION_NEXT : Tests {
    my $c = gsl_combination_calloc(6,3);
    is_deeply( [ map{ gsl_combination_get($c,$_) } (0..1) ] , [ 0 .. 1 ] );
    ok_status(gsl_combination_next($c));
    is_deeply( [ map{ gsl_combination_get($c,$_) } (0..2) ] , [ 0, 1, 3 ] );
}

sub NEW : Tests {
    my $c = Math::GSL::Combination->new(5,5);
    isa_ok($c, 'Math::GSL::Combination');
    is_deeply( [ map { gsl_combination_get($c->raw, $_) } (0..4) ],
        [ 0 .. 4 ] );
}

sub AS_LIST: Tests {
    my $self = shift;
    is_deeply( [ $self->{obj}->as_list ] , [ 0 .. 4 ] );
}

sub LENGTH : Tests {
    my $self = shift;
    ok($self->{obj}->length eq 10);
}

sub ELEMENTS : Tests {
    my $self = shift;
    ok($self->{obj}->elements eq 5);
}

sub NEXT_STATUS : Tests {
    my $c = Math::GSL::Combination->new(6,3);
    $c->next();
    ok( $c->status() == 0 );
}

sub PREV_STATUS : Tests {
    my $c = Math::GSL::Combination->new(6,3);
    $c->next();
    $c->prev();
    ok( $c->status() == 0 );
}

sub FWRITE : Tests {
    my $c = Math::GSL::Combination->new(6,3);
    my $new = Math::GSL::Combination->new(6,3);
    my $fd = gsl_fopen('combo.txt', 'w') or die $!;
    ok_status( gsl_combination_fwrite($fd, $c->raw) );
    gsl_fclose($fd);
    $fd = gsl_fopen('combo.txt', 'r') or die $!;
    ok_status(gsl_combination_fread($fd, $new->raw));
    is_deeply ( [ $c->as_list ], [ $new->as_list ] );
}

sub NEXT : Tests {
    my $c = Math::GSL::Combination->new(6,3);
    
    is_deeply( [ $c->as_list ] , [ 0 .. 2 ] );
    $c->next;
    ok_status( $c->status );
    is_deeply( [ $c->as_list ] , [ 0 , 1, 3 ] );
}

Test::Class->runtests;
Something went wrong with that request. Please try again.