Mercurial > pub > dyncall > dyncall
comparison test/common/rand-sig.lua @ 495:45ac093ca822
- test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
author | Tassilo Philipp |
---|---|
date | Mon, 21 Mar 2022 16:50:44 +0100 |
parents | d45c582b5457 |
children | da5232da6270 |
comparison
equal
deleted
inserted
replaced
494:d45c582b5457 | 495:45ac093ca822 |
---|---|
4 -- minargs | 4 -- minargs |
5 -- maxargs | 5 -- maxargs |
6 -- ncases | 6 -- ncases |
7 -- types | 7 -- types |
8 -- seed | 8 -- seed |
9 | |
10 -- optional: | |
11 -- rtypes (if not set, it'll be 'v'..types) | |
9 | 12 |
10 -- optional (when including aggregate generation): | 13 -- optional (when including aggregate generation): |
11 -- minaggrfields | 14 -- minaggrfields |
12 -- maxaggrfields | 15 -- maxaggrfields |
13 -- maxarraylen | 16 -- maxarraylen |
34 types = types..pairs_cl[i] | 37 types = types..pairs_cl[i] |
35 end | 38 end |
36 end | 39 end |
37 | 40 |
38 | 41 |
39 rtypes = "v"..types | 42 if rtypes == nil then |
43 rtypes = "v"..types | |
44 end | |
45 | |
40 | 46 |
41 function mkaggr(n_nest, maxdepth, o, c) | 47 function mkaggr(n_nest, maxdepth, o, c) |
42 local s = o | 48 local s = o |
43 local nfields = 0 | 49 local nfields = 0 |
44 | 50 |
45 repeat | 51 repeat |
46 local t = c | 52 local t = c |
47 if nfields < maxaggrfields then | 53 if nfields < maxaggrfields then |
48 repeat | 54 repeat |
49 local id = math.random(#types) | 55 local id = math.random(#types) |
50 t = types:sub(id,id) | 56 t = types:sub(id,id) |
51 until t ~= c or nfields >= minaggrfields | 57 until t ~= c or nfields >= minaggrfields |
52 end | 58 end |
53 | 59 |
54 s_ = mktype(t, n_nest, maxdepth, o) | 60 s_ = mktype(t, n_nest, maxdepth, o) |
55 if(#s_ > 0) then | 61 if(#s_ > 0) then |
56 nfields = nfields + 1 | 62 nfields = nfields + 1 |
57 end | 63 end |
58 s = s..s_ | 64 s = s..s_ |
59 | 65 |
60 -- member (which cannot be first char) as array? Disallow multidimensional arrays @@@STRUCT allow multidim? | 66 -- member (which cannot be first char) as array? Disallow multidimensional arrays @@@STRUCT allow multidim? |
61 if #s > 1 and t ~= c and s:sub(-1) ~= ']' and math.random(arraydice) == 1 then | 67 if #s > 1 and t ~= c and s:sub(-1) ~= ']' and math.random(arraydice) == 1 then |
62 s = s..'['..math.random(maxarraylen)..']' | 68 s = s..'['..math.random(maxarraylen)..']' |
119 end | 125 end |
120 l = table.concat(sig) | 126 l = table.concat(sig) |
121 -- reject dupes, sigs without any aggregate (as this is about aggrs after all), and empty ones (if not wanted) | 127 -- reject dupes, sigs without any aggregate (as this is about aggrs after all), and empty ones (if not wanted) |
122 until (reqaggrinsig ~= true or string.match(l, aggr_op_pattern) ~= nil) and uniq_sigs[l] == nil | 128 until (reqaggrinsig ~= true or string.match(l, aggr_op_pattern) ~= nil) and uniq_sigs[l] == nil |
123 uniq_sigs[l] = 1 | 129 uniq_sigs[l] = 1 |
124 io.write(l.."\n") | 130 |
131 -- @@@ hack: if included from callback_suite, 'mode' is set, and has value "random"; make sig | |
132 -- be in expected format | |
133 -- @@@ all sigs should follow that dyncally format | |
134 if mode ~= nil and mode == 'random' then | |
135 io.write(l:sub(2)..')'..l:sub(1,1).."\n") | |
136 else | |
137 io.write(l.."\n") | |
138 end | |
125 end | 139 end |
126 | 140 |