--- /dev/null
+#! /usr/bin/perl
+#
+# Generate a random test file for dynamic array testing.
+#
+# Syntax reference:
+#
+# push n, pop, shift, unshift n -- normal stack ops (pop and shift print)
+# insert x y z ... -- insert items at beginning
+# append x y z ... -- append items at end
+# delete n -- remove n items from beginning
+# reduce n -- remove n items from end
+# set i n -- assign item at index i to be n
+# get i -- display item at index i
+# show -- write entire array to stdout, space separated on one line
+
+sub random ($) {
+ my $lim = shift;
+ return int(rand($lim));
+}
+
+$lines = shift || 100;
+$max = 0; # Estimate of size of array
+$serial = 1;
+while ($lines) {
+ $what = random(17);
+ if ($what < 8) {
+ my $op = (qw(push pop shift unshift))[$what % 4];
+ if ($op eq "push" || $op eq "unshift") {
+ my $n = $serial++;
+ $max++;
+ print "$op $n\n";
+ } elsif ($max > 0) {
+ $max--;
+ print "$op\n";
+ }
+ } elsif ($what < 10) {
+ my @n = ($serial++);
+ my $op = (qw(insert append))[$what % 2];
+ push(@n, $serial++) while random(4) < 3;
+ print "$op ", join(" ", @n), "\n";
+ $max += @n;
+ } elsif ($what < 12) {
+ if ($max < 10000) { next; }
+ my $n = 1;
+ my $op = (qw(delete reduce))[$what % 2];
+ $n++ while random(4) < 3;
+ print "$op $n\n";
+ $max -= $n;
+ if ($max < 0) {
+ $max = 0;
+ }
+ } elsif ($what < 16) {
+ my $i = random($max);
+ $i++ while random(4) < 2;
+ if ($what % 2 == 0) {
+ my $n = $serial++;
+ print "set $i $n\n";
+ if ($i >= $max) {
+ $max = $i + 1;
+ }
+ } else {
+ print "get $i\n";
+ }
+ } elsif (random(10) == 0) {
+ print "show\n";
+ } else { next; }
+ $lines--;
+}
+
+print "show\n";