4 ### Generate input script and expected output for hash tables.
9 if SYS.version_info >= (3,): xrange = range
11 ###--------------------------------------------------------------------------
12 ### Command-line parsing.
15 def arg(default = None):
24 SEED = int(arg(str(R.randrange(0, 1 << 32))), 0)
27 LINES = int(arg(1000))
29 ###--------------------------------------------------------------------------
33 def char(): return 'abcdefghijklmnopqrstuvwxyz'[R.randrange(0, 26)]
34 word = char() + char() + char()
35 while R.randrange(0, 6) != 0: word += char()
38 ## for i in ['/usr/share/dict/words', '/usr/dict/words']:
40 ## WORDS = [line[:-1] for line in open(i)]
46 ## return WORDS[R.randrange(0, len(WORDS))]
49 ###--------------------------------------------------------------------------
55 SCRIPT = open('sym.script', 'w')
56 WIN = open('expout', 'w')
58 ###--------------------------------------------------------------------------
59 ### Utility functions.
64 Operation decorator. Add the following function to the operations table,
65 with the given probability WEIGHT. This works as follows: if TOTAL is the
66 total of all the WEIGHTs, then this operation has a probability of
67 WEIGHT/TOTAL of being selected.
70 OPS.append((weight, cls))
75 """Return the next number in a simple sequence."""
80 ###--------------------------------------------------------------------------
81 ### The actual operations.
87 SCRIPT.write('set %s %d\n' % (w, n))
94 WIN.write('%d\n' % MAP[w])
96 if R.randrange(8): return
97 WIN.write('*MISSING*\n')
98 SCRIPT.write('get %s\n' % (w))
106 if R.randrange(8): return
107 WIN.write('*MISSING*\n')
108 SCRIPT.write('del %s\n' % (w))
112 SCRIPT.write('count\n')
113 WIN.write('%d\n' % len(MAP))
117 SCRIPT.write('show\n')
119 WIN.write('*EMPTY*\n')
121 kk = list(MAP.keys())
123 WIN.write(' '.join(['%s:%d' % (k, MAP[k]) for k in kk]) + '\n')
125 ###--------------------------------------------------------------------------
126 ### Generate the output.
131 for i in xrange(LINES):
132 OPTAB[R.randrange(0, len(OPTAB))]()
137 open('sym.seed', 'w').write('sym-gtest seed = %08x\n' % SEED)
139 ###----- That's all, folks --------------------------------------------------