File: 17-list-context.t

package info (click to toggle)
libtest-mockrandom-perl 1.01-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 256 kB
  • sloc: perl: 326; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 912 bytes parent folder | download | duplicates (3)
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
# Test::MockRandom
use strict;

use Test::More;

plan tests => 8;

#--------------------------------------------------------------------------#
# Test rand(@list) uses scalar context (in RandomList.pm)
#--------------------------------------------------------------------------#

use Test::MockRandom qw( CORE::GLOBAL );
use lib qw( ./t );
use RandomList;

for ( __PACKAGE__, "RandomList" ) {
    is( UNIVERSAL::can( $_, 'rand' ),
        undef, "rand should not have been imported into $_" );
}
for (qw ( srand oneish )) {
    can_ok( __PACKAGE__, $_ );
}

my $list = RandomList->new( 0, 1, 2, 3, 4, 5 );
isa_ok( $list, 'RandomList' );

srand(0);
is( $list->random(), 0, 'testing $list->random() -- return first element' );

srand( oneish() );
is( $list->random(), 5, 'testing $list->random() -- return last element' );

srand(.49);
is( $list->random(), 2, 'testing $list->random() -- return third element' );