# $RCSfile: each.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:47 $
-print "1..7\n";
+print "1..14\n";
$h{'abc'} = 'ABC';
$h{'def'} = 'DEF';
%h = (1,1);
$size = ((split('/',scalar %h))[1]);
if ($size == 8) {print "ok 7\n";} else {print "not ok 7\n";}
+
+# test scalar each
+%hash = 1..20;
+$total = 0;
+$total += $key while $key = each %hash;
+print "# Scalar each is bad.\nnot " unless $total == 100;
+print "ok 8\n";
+
+for (1..3) { @foo = each %hash }
+keys %hash;
+$total = 0;
+$total += $key while $key = each %hash;
+print "# Scalar keys isn't resetting the iterator.\nnot " if $total != 100;
+print "ok 9\n";
+
+for (1..3) { @foo = each %hash }
+$total = 0;
+$total += $key while $key = each %hash;
+print "# Iterator of each isn't being maintained.\nnot " if $total == 100;
+print "ok 10\n";
+
+for (1..3) { @foo = each %hash }
+values %hash;
+$total = 0;
+$total += $key while $key = each %hash;
+print "# Scalar values isn't resetting the iterator.\nnot " if $total != 100;
+print "ok 11\n";
+
+$size = (split('/', scalar %hash))[1];
+keys(%hash) = $size / 2;
+print "not " if $size != (split('/', scalar %hash))[1];
+print "ok 12\n";
+keys(%hash) = $size + 100;
+print "not " if $size == (split('/', scalar %hash))[1];
+print "ok 13\n";
+
+print "not " if keys(%hash) != 10;
+print "ok 14\n";
+
# $RCSfile: oct.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:08 $
-print "1..6\n";
+print "1..8\n";
print +(oct('01234') == 01234) ? "ok" : "not ok", " 1\n";
print +(oct('0x1234') == 0x1234) ? "ok" : "not ok", " 2\n";
print +(oct('20000000000') == 020000000000) ? "ok" : "not ok", " 4\n";
print +(oct('x80000000') == 0x80000000) ? "ok" : "not ok", " 5\n";
print +(hex('80000000') == 0x80000000) ? "ok" : "not ok", " 6\n";
+print +(oct('1234') == 668) ? "ok" : "not ok", " 7\n";
+print +(hex('1234') == 4660) ? "ok" : "not ok", " 8\n";
#!./perl
print "1..15\n";
-$_=join "", grep $_=chr($_), 32..127;
+$_=join "", map chr($_), 32..127;
-#95 characters - 52 letters - 10 digits = 33 backslashes
-#95 characters + 33 backslashes = 128 characters
+# 96 characters - 52 letters - 10 digits - 1 underscore = 33 backslashes
+# 96 characters + 33 backslashes = 129 characters
$_=quotemeta $_;
-if ( length == 128 ){print "ok 1\n"} else {print "not ok 1\n"}
-if (tr/\\//cd == 94){print "ok 2\n"} else {print "not ok 2\n"}
+if ( length == 129 ){print "ok 1\n"} else {print "not ok 1\n"}
+# 95 non-backslash characters
+if (tr/\\//cd == 95){print "ok 2\n"} else {print "not ok 2\n"}
-#perl5a11 bus errors on this:
if (length quotemeta "" == 0){print "ok 3\n"} else {print "not ok 3\n"}
print "aA\UbB\LcC\EdD" eq "aABBccdD" ? "ok 4\n" : "not ok 4 \n";
# From: kgb@ast.cam.ac.uk (Karl Glazebrook)
-print "1..4\n";
+print "1..6\n";
srand;
-$m=0;
+$m=$max=0;
for(1..1000){
$n = rand(1);
- if ($n<0 || $n>=1) {
+ if ($n<0) {
print "not ok 1\n# The value of randbits is likely too low in config.sh\n";
exit
}
$m += $n;
-
+ $max = $n if $n > $max;
}
$m=$m/1000;
print "ok 1\n";
+$off = log($max)/log(2);
+if ($off > 0) { $off = int(.5+$off) }
+ else { $off = - int(.5-$off) }
+print "# Consider adding $off to randbits\n" if $off > 0;
+print "# Consider subtracting ", -$off, " from randbits\n" if $off < 0;
+
if ($m<0.4) {
print "not ok 2\n# The value of randbits is likely too high in config.sh\n";
}
elsif ($m>0.6) {
- print "not ok 2\n# Something's really weird about rand()'s distribution.\n";
+ print "not ok 2\n# The value of randbits is likely too low in config.sh\n";
}else{
print "ok 2\n";
}
print "ok 4\n";
}
+srand(3.14159);
+$r = rand;
+srand(3.14159);
+print "# srand is not consistent.\nnot " if rand != $r;
+print "ok 5\n";
+
+print "# rand is unchanging!\nnot " if rand == $r;
+print "ok 6\n";