This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
NetWare port from Guruprasad S <SGURUPRASAD@novell.com>.
[perl5.git] / t / op / rand.t
index 23a09b7..e365e59 100755 (executable)
@@ -17,7 +17,7 @@
 
 BEGIN {
     chdir "t" if -d "t";
-    @INC = "../lib" if -d "../lib";
+    @INC = '../lib';
 }
 
 use strict;
@@ -52,6 +52,17 @@ sub bits ($) {
     $max = $min = rand(1);
     for (1..$reps) {
        my $n = rand(1);
+       if ($n < 0.0 or $n >= 1.0) {
+           print <<EOM;
+# WHOA THERE!  \$Config{drand01} is set to '$Config{drand01}',
+# but that apparently produces values < 0.0 or >= 1.0.
+# Make sure \$Config{drand01} is a valid expression in the
+# C-language, and produces values in the range [0.0,1.0).
+#
+# I give up.
+EOM
+           exit;
+       }
        $sum += $n;
        $bits += bits($n * 256);        # Don't be greedy; 8 is enough
                    # It's too many if randbits is less than 8!
@@ -74,8 +85,8 @@ sub bits ($) {
     # reason that the diagnostic message might get the
     # wrong value is that Config.pm is incorrect.)
     #
-    if ($max <= 0 or $max >= (1 << $randbits)) {       # Just in case...
-       print "not ok 1\n";
+    if ($max <= 0 or $max >= (2 ** $randbits)) {# Just in case...
+       print "# max=[$max] min=[$min]\nnot ok 1\n";
        print "# This perl was compiled with randbits=$randbits\n";
        print "# which is _way_ off. Or maybe your system rand is broken,\n";
        print "# or your C compiler can't multiply, or maybe Martians\n";
@@ -91,7 +102,7 @@ sub bits ($) {
     $off = int($off) + ($off > 0);             # Next more positive int
     if ($off) {
        $shouldbe = $Config{randbits} + $off;
-       print "not ok 1\n";
+       print "# max=[$max] min=[$min]\nnot ok 1\n";
        print "# This perl was compiled with randbits=$randbits on $^O.\n";
        print "# Consider using randbits=$shouldbe instead.\n";
        # And skip the remaining tests; they would be pointless now.
@@ -210,7 +221,7 @@ sub bits ($) {
 {
     srand;             # These three lines are for test 7
     my $time = time;   # It's just faster to do them here.
-    my $rand = rand;
+    my $rand = join ", ", rand, rand, rand;
 
     # Hints for TEST 5
     # 
@@ -251,7 +262,7 @@ sub bits ($) {
     #
     while ($time == time) { }  # Wait for new second, just in case.
     srand;
-    if (rand == $rand) {
+    if ((join ", ", rand, rand, rand) eq $rand) {
        print "not ok 7\n";
        print "# srand without args isn't varying.\n";
     } else {
@@ -331,6 +342,7 @@ AUTOSRAND:
     for (1..5) {
        my $PERL = (($^O eq 'VMS') ? "MCR $^X"
                    : ($^O eq 'MSWin32') ? '.\perl'
+                   : ($^O eq 'NetWare') ? 'perl'
                    : './perl');
        $pid = open PERL, qq[$PERL -e "print rand"|];
        die "Couldn't pipe from perl: $!" unless defined $pid;