1 | :- multifile generate/2. | |
2 | :- multifile shrink/3. | |
3 | ||
4 | :- use_module(library(avl)). | |
5 | ||
6 | % Options: | |
7 | % size:X with X the amount of elements in the tree | |
8 | ||
9 | % random avl tree | |
10 | generate(avl_tree(Options),Value) :- | |
11 | is_list(Options) , | |
12 | generate(avl_tree(any([]),Options),Value). | |
13 | ||
14 | generate(avl_tree(Type),Value) :- | |
15 | generate(avl_tree(Type,[]),Value). | |
16 | ||
17 | % avl tree with given type and options | |
18 | generate(avl_tree(Type,Options),AVL) :- | |
19 | (member(size:Size,Options) | |
20 | -> Size >= 0 | |
21 | ; random(1,50,Size)) , | |
22 | length(Value,Size), | |
23 | maplist(generate(Type),Value), | |
24 | findall(Key-true,member(Key,Value),Pairs), | |
25 | list_to_avl(Pairs,AVL). | |
26 | ||
27 | % check empty avl | |
28 | shrink(Type,_,E) :- | |
29 | Type =..[avl_tree|_] , | |
30 | empty_avl(E). | |
31 | % remove some member | |
32 | shrink(Type,Old,New) :- | |
33 | Type =..[avl_tree|_] , | |
34 | avl_member(Key,Old), | |
35 | avl_delete(Key,Old,_,New). |