File: 03-UniformInt.t

package info (click to toggle)
libmath-random-oo-perl 0.22-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 216 kB
  • sloc: perl: 671; makefile: 2
file content (91 lines) | stat: -rw-r--r-- 2,286 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl
use strict;
use warnings;
use blib;  

# Math::Random::OO::UniformInt  
my ($test_array, $test_program);

BEGIN {
    $test_array = [
        { 
            new_args    => [], 
            data       =>  [   
                [0.2, 0],
                [0.5, 1],
            ]
        },
        { 
            new_args    => [1], 
            data       =>  [   
                [0.4, 0],
                [0.5, 1],
            ]
        },
        { 
            new_args    => [2], 
            data       =>  [   
                [0.25, 0],
                [0.34, 1],
                [0.67, 2]
            ]
        },
        { 
            new_args    => [1, 6], 
            data       =>  [   
                [0.1, 1],
                [0.3, 2],
                [0.5, 4],
                [0.7, 5]
            ]
        },
        { 
            new_args    => [-1, 1], 
            data       =>  [   
                [0.33, -1],
                [0.34, 0],
                [0.67, 1]
            ]
        },
        { 
            new_args    => [1,-1], 
            data       =>  [   
                [0.33, -1],
                [0.34, 0],
                [0.67, 1]
            ]
        },
        { 
            new_args    => [-1.56,1.23], 
            data       =>  [   
                [0.33, -1],
                [0.34, 0],
                [0.67, 1]
            ]
        },
    ];    
    $test_program = 0;
    $test_program += @{$_->{data}} + 1 for @$test_array;
}

use Test::More tests => (4 + $test_program);
use Test::Number::Delta within => 1e-5;
use Test::MockRandom 'Math::Random::OO::UniformInt';
BEGIN { Test::MockRandom->export_srand_to('Math::Random::OO::UniformInt') }
BEGIN { use_ok( 'Math::Random::OO::UniformInt' ); }

my $obj = Math::Random::OO::UniformInt->new ();
isa_ok ($obj, 'Math::Random::OO::UniformInt');
isa_ok ($obj->new, 'Math::Random::OO::UniformInt');
can_ok ($obj, qw( seed next ));

for my $case ( @$test_array ) {
    ok( $obj = $obj->new(@{$case->{new_args}}), 
        'creating object with new('.join(", ",@{$case->{new_args}}).')');
    for my $data (@{$case->{data}}) {
        my ($seed,$val) = @$data;
        $obj->seed($seed);
        delta_ok( $obj->next, $val, "does srand($seed),next() give $val?" );
    }
}