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 | |
18 | open(DICT, "/usr/dict/words") or die("open(/usr/dict/words): $!"); |
19 | @w = <DICT>; |
20 | chomp(@w); |
21 | close(DICT); |
22 | |
23 | %a = (); |
24 | |
25 | $lines = shift || 100; |
26 | $serial = 1; |
27 | while ($lines) { |
28 | $what = random(4); |
29 | if ($what == 0) { |
30 | my $k = $w[random(@w)]; |
31 | my $i = $serial++; |
32 | print "set $k $i\n"; |
33 | $a{$k} = $i; |
34 | } elsif ($what == 1) { |
35 | my $k = $w[random(@w)]; |
36 | if (!exists($a{$w}) && random(8) != 0) { next; } |
37 | print "get $k\n"; |
38 | } elsif ($what == 2) { |
39 | my $k = $w[random(@w)]; |
40 | if (!exists($a{$w}) && random(8) != 0) { next; } |
41 | print "del $k\n"; |
42 | delete($w{$k}); |
43 | } elsif (random(5) == 0) { |
44 | print "count\n"; |
45 | } else { next; } |
46 | $lines--; |
47 | } |
48 | |
49 | print "show\n"; |