Commits

Shlomi Fish committed 500ae51

Made shuffle return $deck.

Comments (0)

Files changed (2)

abc-path/Games-ABC_Path-Generator/lib/Games/ABC_Path/MicrosoftRand.pm

     return ($self->rand() % $max);
 }
 
-sub shuffle {
+sub shuffle
+{
     my ($self, $deck) = @_;
-    return unless @$deck; # must not be empty!
 
-    my $i = @$deck;
-    while (--$i) {
-        my $j = $self->max_rand($i+1);
-        @$deck[$i,$j] = @$deck[$j,$i];
+    if (@$deck)
+    {
+        my $i = @$deck;
+        while (--$i) {
+            my $j = $self->max_rand($i+1);
+            @$deck[$i,$j] = @$deck[$j,$i];
+        }
     }
 
-    return;
+    return $deck;
 }
 
 =head1 SUBROUTINES/METHODS

abc-path/Games-ABC_Path-Generator/t/ms-rand.t

 use strict;
 use warnings;
 
-use Test::More tests => 4;
+use Test::More tests => 5;
 
 use Test::Differences;
 
 
     my @array = (0 .. 9);
 
-    $r->shuffle(\@array);
+    my $ret = $r->shuffle(\@array);
     # TEST
     eq_or_diff(
         \@array,
         [1,7,9,8,4,5,3,2,0,6],
         'Array was shuffled.',
     );
+
+    # TEST
+    is ($ret, (\@array), 'shuffle returns the same array.');
 }