1 | :- multifile generate/2. | |
2 | :- multifile shrink/3. | |
3 | ||
4 | :- use_module(library(random),[random_member/2]). | |
5 | ||
6 | % all options of any given type can be used for generation | |
7 | ||
8 | generate(prob_ast_any(Options),Value) :- | |
9 | generate(ground_type,GroundType) , | |
10 | (member(noset,Options) | |
11 | -> generate(ground_type(Options),Type) | |
12 | ; random_member(Type,[integer(Options),string(Options),boolean(Options), | |
13 | set([any|Options]),seq([any|Options]), % any set/seq or expression | |
14 | set(set(GroundType)),seq(seq(GroundType))])) , % max depth is 2 by now | |
15 | gen_type(Type,ast,NType) , | |
16 | generate(NType,Value). | |
17 | ||
18 | % generate random type for an ast leave | |
19 | generate(ground_type,Type) :- | |
20 | random_member(Type,[integer([]),string([]),boolean([])]). | |
21 | generate(ground_type(Options),Type) :- | |
22 | random_member(Type,[integer(Options),string(Options),boolean(Options)]). |