1 | :- multifile generate/2. | |
2 | :- multifile shrink/3. | |
3 | ||
4 | :- use_module(library(lists),[delete/3]). | |
5 | :- use_module(library(random),[random_member/2]). | |
6 | :- use_module(library(sets),[subset/2]). | |
7 | ||
8 | % Options: | |
9 | % small, positive, negative, nozero, between(A,B) none (i.e. []) for any integer | |
10 | % expr for a well-defined ast integer expression, | |
11 | % random to get either an ast integer node or an integer expression | |
12 | ||
13 | generate(prob_ast_integer(Options),Value) :- | |
14 | member(expr,Options) , ! , | |
15 | delete(Options,expr,DOptions) , | |
16 | % if no definedness is given set to well-defined | |
17 | (member(_-defined,DOptions) | |
18 | -> NOptions = DOptions | |
19 | ; NOptions = [well-defined|DOptions]) , | |
20 | generate(prob_ast_int_expr(NOptions),Value). | |
21 | ||
22 | generate(prob_ast_integer(Options),Value) :- | |
23 | \+member(random,Options) , ! , | |
24 | generate(integer(Options),Gen) , | |
25 | Value = b(integer(Gen),integer,[]). | |
26 | ||
27 | generate(prob_ast_integer(Options),Value) :- | |
28 | % delete random from options to terminate | |
29 | delete(Options,random,NOptions) , | |
30 | % higher chance to generate expression | |
31 | random(0,10,R) , | |
32 | (R > 2 | |
33 | -> RandomOption = [expr|NOptions] | |
34 | ; RandomOption = NOptions) , | |
35 | generate(prob_ast_integer(RandomOption),Value). | |
36 | ||
37 | shrink(prob_ast_integer(_),b(integer(Value),integer,Info),b(integer(Shrunken),integer,Info)) :- | |
38 | shrink(integer(_),Value,Shrunken). | |
39 | ||
40 | shrink(prob_ast_integer(_),Value,Shrunken) :- | |
41 | shrink(prob_ast_int_expr,Value,Shrunken). |