comparison test/suite_aggrs/rand-sig.lua @ 434:3d2c5d156d78

- test/suite_aggrs: support for nested structs, now
author Tassilo Philipp
date Sun, 23 Jan 2022 23:20:02 +0100
parents 167faab0c0be
children b4ddad459690
comparison
equal deleted inserted replaced
433:45662241d9cd 434:3d2c5d156d78
1 require"config" 1 require"config"
2 2
3 -- assure aggr chars are present in pairs (can be weighted, though), to avoid 3 -- assure aggr chars are present in pairs (can be weighted, though), to avoid
4 -- inf loops 4 -- inf loops
5 if string.match(types,'{') and not string.match(types,'}') then types = types..'}' end 5 if string.match(types,'{') and not string.match(types,'}') then types = types..'}' end
6 -- @@@ unions, arrays
6 7
7 rtypes = "v"..types 8 rtypes = "v"..types
8 9
9 10
10 function mkstruct(n_nest) 11 function mkstruct(n_nest, maxdepth)
11 local s = "{" 12 local s = "{"
12 13
13 repeat 14 repeat
14 local id = math.random(#types) 15 local id = math.random(#types)
15 local t = types:sub(id,id) 16 local t = types:sub(id,id)
16 s = s..mktype(t, n_nest) 17 s = s..mktype(t, n_nest, maxdepth)
17 until t == '}' 18 until t == '}'
18 19
19 return s 20 return s
20 end 21 end
21 22
22 function mktype(t, n_nest) 23 function mktype(t, n_nest, maxdepth)
23 -- ignore new structs if above depth limit 24 -- ignore new structs if above depth limit
24 if t == '{' then 25 if t == '{' then
25 if n_nest < maxaggrdepth then 26 if n_nest < maxdepth then
26 return mkstruct(n_nest + 1) 27 return mkstruct(n_nest + 1, maxdepth)
27 else 28 else
28 return '' 29 return ''
29 end 30 end
30 end 31 end
31 32
39 40
40 41
41 math.randomseed(seed) 42 math.randomseed(seed)
42 local id 43 local id
43 for i = 1, ncases do 44 for i = 1, ncases do
44 id = math.random(#rtypes)
45 local nargs = math.random(minargs,maxargs) 45 local nargs = math.random(minargs,maxargs)
46 local sig = { mktype(rtypes:sub(id,id), 0) } 46 local l = ''
47 for j = 1, nargs do 47 repeat
48 id = math.random(#types) 48 id = math.random(#rtypes)
49 sig[#sig+1] = mktype(types:sub(id,id), 0) 49 local sig = { mktype(rtypes:sub(id,id), 0, math.random(maxaggrdepth)) } -- random depth avoids excessive nesting
50 end 50 for j = 1, nargs do
51 io.write(table.concat(sig)) 51 id = math.random(#types)
52 io.write("\n") 52 sig[#sig+1] = mktype(types:sub(id,id), 0, math.random(maxaggrdepth)) -- random depth avoids excessive nesting
53 end
54 l = table.concat(sig)
55 -- reject sigs without any aggregate, as this is about aggrs after all
56 until string.match(l, '{') ~= nil
57 io.write(l.."\n")
53 end 58 end
54 59