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
|
#!/usr/bin/perl
use strict;
use warnings;
use blib;
# Math::Random::OO::Bootstrap
use Test::MockRandom 'Math::Random::OO::Bootstrap';
BEGIN { Test::MockRandom->export_srand_to('Math::Random::OO::Bootstrap') }
my ($test_array, $test_program);
BEGIN {
$test_array = [
{
name => "list",
new_args => [ 1, 2, 2, 3 ],
data => [
[0.2, 1],
[0.5, 2],
[oneish, 3]
]
},
{
name => "arrayref",
new_args => [ [1, 2, 2, 3 ] ],
data => [
[0.2, 1],
[0.5, 2],
[oneish, 3]
]
},
];
$test_program = 0;
$test_program += @{$_->{data}} + 1 for @$test_array;
}
use Test::More tests => (5 + $test_program);
use Test::Number::Delta within => 1e-5;
BEGIN { use_ok( 'Math::Random::OO::Bootstrap' ); }
my $obj;
eval { Math::Random::OO::Bootstrap->new() };
ok( $@, 'does new die with no arguments?' );
$obj = Math::Random::OO::Bootstrap->new(1);
isa_ok ($obj, 'Math::Random::OO::Bootstrap');
isa_ok ($obj->new(1), 'Math::Random::OO::Bootstrap');
can_ok ($obj, qw( seed next ));
for my $case ( @$test_array ) {
ok( $obj = $obj->new(@{$case->{new_args}}),
'creating object with '.$case->{name}.' args to new()');
for my $data (@{$case->{data}}) {
my ($seed,$val) = @$data;
$obj->seed($seed);
delta_ok( $obj->next, $val, "does srand($seed),next() give $val?" );
}
}
|