1 | :- multifile generate/2. | |
2 | :- multifile shrink/3. | |
3 | ||
4 | :- use_module(library(random),[random_member/2]). | |
5 | ||
6 | % Options: | |
7 | % noset to generate no lists or trees | |
8 | ||
9 | generate(any(Options),Value) :- | |
10 | TypeList = [atom,boolean,float,integer,rational,number] , | |
11 | member(noset,Options) , | |
12 | delete(Options,noset,NOptions) , % no nested data structures | |
13 | random_member(Temp,TypeList) , | |
14 | Type =.. [Temp,NOptions] , | |
15 | generate(Type,Value). | |
16 | generate(any(Options),Value) :- | |
17 | TypeList = [atom,boolean,float,integer,rational,number] , | |
18 | \+member(noset,Options) , | |
19 | random_member(TempType,[list,avl_tree,tree|TypeList]) , | |
20 | random_member(SubType,TypeList) , % random subtype for nested data structures | |
21 | nested_type(TempType,Options,SubType,Type) , | |
22 | generate(Type,Value). | |
23 | ||
24 | nested_type(TempType,Options,SubType,Type) :- | |
25 | member(TempType,[list,avl_tree,tree]) , | |
26 | InnerType =.. [SubType,Options] , | |
27 | Type =.. [TempType,InnerType,Options]. | |
28 | nested_type(TempType,Options,_,Type) :- | |
29 | \+member(TempType,[list,avl_tree,tree]) , | |
30 | Type =.. [TempType,Options]. |