cd300147 |
1 | #! /usr/bin/perl |
2 | # |
3 | # Generate a random test file for symbol table testing. |
4 | # |
5 | # Syntax reference: |
6 | # |
7 | # set k v -- assign (textual) key k the (integer) value i |
8 | # get k -- display value at key k |
9 | # del k -- remove key k |
10 | # count -- show number of items |
11 | # show -- dump out the entire table, in alphabetical key order |
12 | |
13 | sub random ($) { |
14 | my $lim = shift; |
15 | return int(rand($lim)); |
16 | } |
17 | |
1c4fa429 |
18 | $words = "/usr/dict/words"; |
19 | -r $words or $words = "/usr/share/dict/words"; |
20 | open(DICT, $words) or die("open($words): $!"); |
cd300147 |
21 | @w = <DICT>; |
22 | chomp(@w); |
23 | close(DICT); |
24 | |
25 | %a = (); |
26 | |
27 | $lines = shift || 100; |
28 | $serial = 1; |
29 | while ($lines) { |
30 | $what = random(4); |
31 | if ($what == 0) { |
32 | my $k = $w[random(@w)]; |
33 | my $i = $serial++; |
34 | print "set $k $i\n"; |
35 | $a{$k} = $i; |
36 | } elsif ($what == 1) { |
37 | my $k = $w[random(@w)]; |
38 | if (!exists($a{$w}) && random(8) != 0) { next; } |
39 | print "get $k\n"; |
40 | } elsif ($what == 2) { |
41 | my $k = $w[random(@w)]; |
42 | if (!exists($a{$w}) && random(8) != 0) { next; } |
43 | print "del $k\n"; |
44 | delete($w{$k}); |
45 | } elsif (random(5) == 0) { |
46 | print "count\n"; |
47 | } else { next; } |
48 | $lines--; |
49 | } |
50 | |
51 | print "show\n"; |