summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Phoenix <rootbeer@teleport.com>1996-12-29 17:46:21 -0800
committerChip Salzenberg <chip@atlantic.net>1997-01-01 08:59:00 +1200
commit3524d3b9766c150548bbd837b65d78ef993d647d (patch)
treea2d6506da30da1584d4c784254b5258564f0e0c6
parentd5c001ddae568c5769b6a9eb70138c72d385cacb (diff)
downloadperl-3524d3b9766c150548bbd837b65d78ef993d647d.tar.gz
More tests
private-msgid: <Pine.GSO.3.95.961229170736.15213M-100000@solaris.teleport.co
-rwxr-xr-xt/op/each.t41
-rwxr-xr-xt/op/oct.t4
-rwxr-xr-xt/op/quotemeta.t12
-rwxr-xr-xt/op/rand.t24
4 files changed, 68 insertions, 13 deletions
diff --git a/t/op/each.t b/t/op/each.t
index 4106e54c50..b92dd1770c 100755
--- a/t/op/each.t
+++ b/t/op/each.t
@@ -2,7 +2,7 @@
# $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';
@@ -68,3 +68,42 @@ undef %h;
%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";
+
diff --git a/t/op/oct.t b/t/op/oct.t
index 7890643aef..24b5c4309d 100755
--- a/t/op/oct.t
+++ b/t/op/oct.t
@@ -2,7 +2,7 @@
# $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";
@@ -10,3 +10,5 @@ print +(hex('01234') == 0x1234) ? "ok" : "not ok", " 3\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";
diff --git a/t/op/quotemeta.t b/t/op/quotemeta.t
index 09794571b1..20dd312b31 100755
--- a/t/op/quotemeta.t
+++ b/t/op/quotemeta.t
@@ -1,15 +1,15 @@
#!./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";
diff --git a/t/op/rand.t b/t/op/rand.t
index 5c0eccf15f..6031f421b1 100755
--- a/t/op/rand.t
+++ b/t/op/rand.t
@@ -2,28 +2,34 @@
# 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";
}
@@ -49,4 +55,12 @@ if ($m<40 || $m>60) {
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";