Debian Codegraph @

cpan/Scalar-List-Utils/t/shuffle.t

raw
1 #!./perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 7;
7
8 use List::Util qw(shuffle);
9
10 my @r;
11
12 @r = shuffle();
13 ok( !@r, 'no args');
14
15 @r = shuffle(9);
16 is( 0+@r, 1, '1 in 1 out');
17 is( $r[0], 9, 'one arg');
18
19 my @in = 1..100;
20 @r = shuffle(@in);
21 is( 0+@r, 0+@in, 'arg count');
22
23 isnt( "@r", "@in", 'result different to args');
24
25 my @s = sort { $a <=> $b } @r;
26 is( "@in", "@s", 'values');
27
28 {
29 local $List::Util::RAND = sub { 4/10 }; # chosen by a fair die
30
31 @r = shuffle(1..10);
32 is_deeply(
33 [ shuffle(1..10) ],
34 [ shuffle(1..10) ],
35 'rigged rand() yields predictable output'
36 );
37 }