File: 11n_over_k.t

package info (click to toggle)
libstatistics-test-randomwalk-perl 0.02-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 120 kB
  • sloc: perl: 199; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 722 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;
use Test::More tests => 231;
BEGIN { use_ok('Statistics::Test::RandomWalk') };

use Math::BigFloat;
use Statistics::Test::Sequence;

sub n_over_k {
    my $n = Math::BigFloat->new(shift);
    my $k = Math::BigFloat->new(shift);
    
    return(
        Statistics::Test::Sequence::faculty($n)
        / (
            Statistics::Test::Sequence::faculty($k)
            * Statistics::Test::Sequence::faculty($n-$k)
        )
    );
}

foreach my $n ( 1..20 ) {
    foreach my $k (0..$n) {
        my $str = Statistics::Test::RandomWalk::n_over_k($n, $k);
        my $test = n_over_k($n, $k);
        ok(
            $str == $test,
            "n_over_k($n, $k) = $str | $test"
        );
    }
}