Mercurial > pub > dyncall > dyncall
comparison test/suite_aggrs/rand-sig.lua @ 463:bd8f5da2c74b
suite_aggr: added configurable limits to number of struct fields (also simplified allowing (or not) empty ones)
author | Tassilo Philipp |
---|---|
date | Tue, 01 Feb 2022 22:35:08 +0100 |
parents | 653b65580cb4 |
children |
comparison
equal
deleted
inserted
replaced
462:653b65580cb4 | 463:bd8f5da2c74b |
---|---|
16 | 16 |
17 rtypes = "v"..types | 17 rtypes = "v"..types |
18 | 18 |
19 function mkaggr(n_nest, maxdepth, o, c) | 19 function mkaggr(n_nest, maxdepth, o, c) |
20 local s = o | 20 local s = o |
21 local nfields = 0 | |
21 | 22 |
22 repeat | 23 repeat |
23 local id = math.random(#types) | 24 local t = c |
24 local t = types:sub(id,id) | 25 if nfields < maxaggrfields then |
25 s = s..mktype(t, n_nest, maxdepth, o) | 26 repeat |
27 local id = math.random(#types) | |
28 t = types:sub(id,id) | |
29 until t ~= c or nfields >= minaggrfields | |
30 end | |
31 | |
32 s_ = mktype(t, n_nest, maxdepth, o) | |
33 if(#s_ > 0) then | |
34 nfields = nfields + 1 | |
35 end | |
36 s = s..s_ | |
26 | 37 |
27 -- member (which cannot be first char) as array? Disallow multidimensional arrays | 38 -- member (which cannot be first char) as array? Disallow multidimensional arrays |
28 if #s > 1 and t ~= c and s:sub(-1) ~= ']' and math.random(arraydice) == 1 then | 39 if #s > 1 and t ~= c and s:sub(-1) ~= ']' and math.random(arraydice) == 1 then |
29 s = s..'['..math.random(maxarraylen)..']' | 40 s = s..'['..math.random(maxarraylen)..']' |
30 end | 41 end |
66 end | 77 end |
67 | 78 |
68 return t | 79 return t |
69 end | 80 end |
70 | 81 |
71 function contains_empty_aggr(s) | |
72 for i = 1, #pairs_op do | |
73 if string.match(s, '%'..pairs_op[i]..'%'..pairs_cl[i]) ~= nil then | |
74 return true | |
75 end | |
76 end | |
77 return false | |
78 end | |
79 | |
80 math.randomseed(seed) | 82 math.randomseed(seed) |
81 local id | 83 local id |
82 local uniq_sigs = { } | 84 local uniq_sigs = { } |
83 for i = 1, ncases do | 85 for i = 1, ncases do |
84 local l = '' | 86 local l = '' |
90 id = math.random(#types) | 92 id = math.random(#types) |
91 sig[#sig+1] = mktype(types:sub(id,id), 0, math.random(maxaggrdepth), nil) -- random depth avoids excessive nesting | 93 sig[#sig+1] = mktype(types:sub(id,id), 0, math.random(maxaggrdepth), nil) -- random depth avoids excessive nesting |
92 end | 94 end |
93 l = table.concat(sig) | 95 l = table.concat(sig) |
94 -- reject dupes, sigs without any aggregate (as this is about aggrs after all), and empty ones (if not wanted) | 96 -- reject dupes, sigs without any aggregate (as this is about aggrs after all), and empty ones (if not wanted) |
95 until string.match(l, aggr_op_pattern) ~= nil and uniq_sigs[l] == nil and (emptyaggrs or not contains_empty_aggr(l)) | 97 until string.match(l, aggr_op_pattern) ~= nil and uniq_sigs[l] == nil |
96 uniq_sigs[l] = 1 | 98 uniq_sigs[l] = 1 |
97 io.write(l.."\n") | 99 io.write(l.."\n") |
98 end | 100 end |
99 | 101 |