Commit | Line | Data |
---|---|---|
8dad2faf SK |
1 | -module(hope_list_SUITE). |
2 | ||
fd66fd0c | 3 | -include_lib("proper/include/proper_common.hrl"). |
f4780d18 | 4 | |
8dad2faf SK |
5 | %% Callbacks |
6 | -export( | |
7 | [ all/0 | |
8 | , groups/0 | |
9 | ]). | |
10 | ||
11 | %% Test cases | |
12 | -export( | |
13 | [ t_unique_preserve_order/1 | |
8bbf6f4d | 14 | , t_hope_list_specs/1 |
c66ddf80 | 15 | , t_map_rev/1 |
2a81fbac | 16 | , t_map_slow/1 |
ff793acf | 17 | , t_map/1 |
fad0cddc | 18 | , t_map_3/1 |
54ab0c82 | 19 | , t_map_result/1 |
8dad2faf SK |
20 | ]). |
21 | ||
22 | ||
23 | -define(GROUP , hope_list). | |
24 | ||
f4780d18 PO |
25 | -define(PROPTEST(A), true = proper:quickcheck(A())). |
26 | ||
ea7f00f1 SK |
27 | -define(type, proper_types). |
28 | ||
8dad2faf SK |
29 | |
30 | %% ============================================================================ | |
31 | %% Common Test callbacks | |
32 | %% ============================================================================ | |
33 | ||
34 | all() -> | |
35 | [{group, ?GROUP}]. | |
36 | ||
37 | groups() -> | |
38 | Tests = | |
39 | [ t_unique_preserve_order | |
8bbf6f4d | 40 | , t_hope_list_specs |
c66ddf80 | 41 | , t_map_rev |
2a81fbac | 42 | , t_map_slow |
ff793acf | 43 | , t_map |
fad0cddc | 44 | , t_map_3 |
54ab0c82 | 45 | , t_map_result |
8dad2faf | 46 | ], |
8bbf6f4d | 47 | Properties = [parallel], |
8dad2faf SK |
48 | [{?GROUP, Properties, Tests}]. |
49 | ||
50 | ||
51 | %% ============================================================================= | |
52 | %% Test cases | |
53 | %% ============================================================================= | |
54 | ||
c66ddf80 | 55 | t_map_rev(_Cfg) -> |
886a9557 PO |
56 | ?PROPTEST(map_rev). |
57 | ||
58 | map_rev() -> | |
ea7f00f1 | 59 | ?FORALL({L, F}, {?type:list(?type:integer()), ?type:function([?type:integer()], ?type:term())}, |
886a9557 | 60 | hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L))). |
c66ddf80 | 61 | |
2a81fbac | 62 | t_map_slow(_Cfg) -> |
886a9557 PO |
63 | ?PROPTEST(map_slow). |
64 | ||
65 | map_slow() -> | |
ea7f00f1 | 66 | ?FORALL({L, F}, {?type:list(?type:integer()), ?type:function([?type:integer()], ?type:term())}, |
886a9557 | 67 | hope_list:map_slow(L, F) == lists:map(F, L)). |
2a81fbac | 68 | |
ff793acf | 69 | t_map(_Cfg) -> |
886a9557 PO |
70 | ?PROPTEST(map). |
71 | ||
72 | map() -> | |
ea7f00f1 | 73 | ?FORALL({L, F}, {?type:list(?type:integer()), ?type:function([?type:integer()], ?type:term())}, |
886a9557 | 74 | hope_list:map(L, F) == lists:map(F, L)). |
ff793acf | 75 | |
fad0cddc PO |
76 | t_map_3(_Cfg) -> |
77 | ?PROPTEST(map_3). | |
78 | ||
79 | map_3() -> | |
ea7f00f1 | 80 | ?FORALL({L, F, N}, {?type:list(?type:integer()), ?type:function([?type:integer()], ?type:term()), ?type:non_neg_integer()}, |
fad0cddc PO |
81 | hope_list:map(L, F, N) == lists:map(F, L)). |
82 | ||
8dad2faf | 83 | t_unique_preserve_order(_Cfg) -> |
f4780d18 PO |
84 | ?PROPTEST(prop_unique_preserve_order). |
85 | ||
86 | prop_unique_preserve_order() -> | |
ea7f00f1 | 87 | ?FORALL(L, ?type:list(), |
f4780d18 PO |
88 | begin |
89 | Duplicates = L -- lists:usort(L), | |
90 | hope_list:unique_preserve_order(L) == | |
91 | lists:reverse(lists:reverse(L) -- Duplicates) | |
92 | end). | |
8bbf6f4d PO |
93 | |
94 | t_hope_list_specs(_) -> | |
95 | [] = proper:check_specs(hope_list). | |
54ab0c82 SK |
96 | |
97 | t_map_result(_Cfg) -> | |
98 | AssertPositive = | |
99 | fun (I) when I > 0 -> {ok, I}; (_) -> {error, negative} end, | |
100 | AllPositives = lists:seq(1, 5), | |
101 | AllNegatives = lists:seq(-5, -1), | |
102 | Mixed = lists:seq(-5, 5), | |
103 | {ok, AllPositives} = hope_list:map_result(AllPositives, AssertPositive), | |
104 | {error, negative} = hope_list:map_result(AllNegatives, AssertPositive), | |
105 | {error, negative} = hope_list:map_result(Mixed, AssertPositive). |