annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
1 require"config"
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
2
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
3 -- assure aggr chars are present in pairs (can be weighted, though), to avoid
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
4 -- inf loops
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
5 if string.match(types,'{') and not string.match(types,'}') then types = types..'}' end
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
6 -- @@@ unions, arrays
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
7
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
8 rtypes = "v"..types
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
9
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
10
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
11 function mkstruct(n_nest, maxdepth)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
12 local s = "{"
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
13
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
14 repeat
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
15 local id = math.random(#types)
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
16 local t = types:sub(id,id)
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
17 s = s..mktype(t, n_nest, maxdepth)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
18 until t == '}'
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
19
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
20 return s
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
21 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
22
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
23 function mktype(t, n_nest, maxdepth)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
24 -- ignore new structs if above depth limit
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
25 if t == '{' then
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
26 if n_nest < maxdepth then
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
27 return mkstruct(n_nest + 1, maxdepth)
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
28 else
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
29 return ''
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
30 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
31 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
32
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
33 -- if '}', without any open, use empty struct
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
34 if n_nest == 0 and t == '}' then
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
35 return "{}"
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
36 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
37
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
38 return t
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
39 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
40
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
41
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
42 math.randomseed(seed)
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
43 local id
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
44 for i = 1, ncases do
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
45 local nargs = math.random(minargs,maxargs)
434
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
46 local l = ''
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
47 repeat
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
48 id = math.random(#rtypes)
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
49 local sig = { mktype(rtypes:sub(id,id), 0, math.random(maxaggrdepth)) } -- random depth avoids excessive nesting
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
50 for j = 1, nargs do
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
51 id = math.random(#types)
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
52 sig[#sig+1] = mktype(types:sub(id,id), 0, math.random(maxaggrdepth)) -- random depth avoids excessive nesting
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
53 end
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
54 l = table.concat(sig)
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
55 -- reject sigs without any aggregate, as this is about aggrs after all
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
56 until string.match(l, '{') ~= nil
3d2c5d156d78 - test/suite_aggrs: support for nested structs, now
Tassilo Philipp
parents: 432
diff changeset
57 io.write(l.."\n")
432
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
58 end
167faab0c0be first usable version of test suite for aggregates, handling only non-nested struct params, at the moment;
Tassilo Philipp
parents:
diff changeset
59