4 ### Generate input script and expected output for hash tables.
9 ###--------------------------------------------------------------------------
10 ### Command-line parsing.
13 def arg(default
= None):
22 SEED
= int(arg(str(R
.randrange(0, 1 << 32))), 0)
25 LINES
= int(arg(1000))
27 ###--------------------------------------------------------------------------
31 def char(): return 'abcdefghijklmnopqrstuvwxyz'[R
.randrange(0, 26)]
32 word
= char() + char() + char()
33 while R
.randrange(0, 6) != 0: word
+= char()
36 ## for i in ['/usr/share/dict/words', '/usr/dict/words']:
38 ## WORDS = [line[:-1] for line in open(i)]
44 ## return WORDS[R.randrange(0, len(WORDS))]
47 ###--------------------------------------------------------------------------
53 SCRIPT
= open('sym.script', 'w')
54 WIN
= open('expout', 'w')
56 ###--------------------------------------------------------------------------
57 ### Utility functions.
62 Operation decorator. Add the following function to the operations table,
63 with the given probability WEIGHT. This works as follows: if TOTAL is the
64 total of all the WEIGHTs, then this operation has a probability of
65 WEIGHT/TOTAL of being selected.
68 OPS
.append((weight
, cls
))
73 """Return the next number in a simple sequence."""
78 ###--------------------------------------------------------------------------
79 ### The actual operations.
85 SCRIPT
.write('set %s %d\n' %
(w
, n
))
92 WIN
.write('%d\n' % MAP
[w
])
94 if R
.randrange(8): return
95 WIN
.write('*MISSING*\n')
96 SCRIPT
.write('get %s\n' %
(w
))
104 if R
.randrange(8): return
105 WIN
.write('*MISSING*\n')
106 SCRIPT
.write('del %s\n' %
(w
))
110 SCRIPT
.write('count\n')
111 WIN
.write('%d\n' %
len(MAP
))
115 SCRIPT
.write('show\n')
117 WIN
.write('*EMPTY*\n')
121 WIN
.write(' '.join(['%s:%d' %
(k
, MAP
[k
]) for k
in kk
]) + '\n')
123 ###--------------------------------------------------------------------------
124 ### Generate the output.
129 for i
in xrange(LINES
):
130 OPTAB
[R
.randrange(0, len(OPTAB
))]()
135 open('sym.seed', 'w').write('sym-gtest seed = %08x\n' % SEED
)
137 ###----- That's all, folks --------------------------------------------------