Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 53 lines (43 sloc) 1.239 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
package Math::GSL::DHT::Test;
use Math::GSL::Test qw/:all/;
use base q{Test::Class};
use Test::More;
use Math::GSL::DHT qw/:all/;
use Math::GSL qw/:all/;
use Data::Dumper;
use Math::GSL::Errno qw/:all/;
use strict;

BEGIN { gsl_set_error_handler_off(); }

sub make_fixture : Test(setup) {
}

sub teardown : Test(teardown) {
}

sub GSL_DHT_ALLOC_FREE : Tests {
    my $dht = gsl_dht_alloc(5);
    isa_ok($dht, 'Math::GSL::DHT');
    gsl_dht_free($dht);
    ok(!$@, 'gsl_dht_free');
}

sub DHT_NEW : Tests {
    my $dht = gsl_dht_new(128, 1.0, 20);
    isa_ok($dht, 'Math::GSL::DHT' );
}

sub DHT_SAMPLE_APPLY : Tests {
    my $f_in = [(0) x 128 ];
    my $f_out = [(0) x 128 ];
    my $dht = gsl_dht_new(128, 1.0, 20);

    for my $n (0..127) {
            my $x = gsl_dht_x_sample($dht, $n);
            $f_in->[$n] = exp(-$x);
    }
    ok( $#$f_in = 127, 'gsl_dht_x_sample' );

    ok_status( gsl_dht_apply($dht, $f_in, $f_out));
    ok( $#$f_out = 127, 'gsl_dht_apply' );

    local $TODO = 'need a typemap for $f_in and $f_out';
    # check that the relative error at most 2%
    ok(
        is_similar_relative ($f_out->[0], 0.181, 0.02),
        "gsl_dht_apply output @{[$f_out->[0]]} != 0.181"
    );
}

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