1 | :- multifile generate/2. | |
2 | :- multifile shrink/3. | |
3 | ||
4 | :- use_module(library(random),[random_member/2]). | |
5 | ||
6 | % all options of any type can be used | |
7 | ||
8 | % in practice a maximum recursive depth of two is enough for sets and sequences | |
9 | generate(prob_value_any(Options),Value) :- | |
10 | (member(noset,Options) | |
11 | -> generate(ground_type(Options),Type) | |
12 | ; random_member(Type,[integer(Options),string(Options),boolean(Options), | |
13 | set(Options),set(set(Options)),seq(Options),seq(seq(Options))])) , | |
14 | gen_type(Type,value,NType) , | |
15 | generate(NType,Value). | |
16 | ||
17 | shrink(Type,int(Value),int(Shrunken)) :- | |
18 | Type =.. [prob_value_any|_] , | |
19 | shrink(integer(_),Value,Shrunken). | |
20 | ||
21 | shrink(Type,string(Value),string(Shrunken)) :- | |
22 | Type =.. [prob_value_any|_] , | |
23 | shrink(atom(_),Value,Shrunken). | |
24 | ||
25 | shrink(Type,Value,Shrunken) :- | |
26 | Type =.. [prob_value_any|_] , | |
27 | (is_list(Value) ; Value = avl_set(_)) , | |
28 | shrink(prob_value_set,Value,Shrunken). | |
29 | ||
30 | shrink(Type,Value,Shrunken) :- | |
31 | Type =.. [prob_value_any|_] , | |
32 | shrink(prob_value_boolean(_),Value,Shrunken). |