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( | |
2fa2f026 SK |
13 | [ t_auto_hope_list_specs/1 |
14 | , t_auto_map/1 | |
15 | , t_auto_map_3/1 | |
16 | , t_auto_map_rev/1 | |
17 | , t_auto_map_slow/1 | |
18 | , t_auto_unique_preserve_order/1 | |
19 | , t_manual_map_result/1 | |
8dad2faf SK |
20 | ]). |
21 | ||
22 | ||
23 | -define(GROUP , hope_list). | |
24 | ||
cf0f905c | 25 | -define(CHECK(F), true = proper:quickcheck(F())). |
f4780d18 | 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 = | |
2fa2f026 SK |
39 | [ t_auto_hope_list_specs |
40 | , t_auto_map | |
41 | , t_auto_map_3 | |
42 | , t_auto_map_rev | |
43 | , t_auto_map_slow | |
44 | , t_auto_unique_preserve_order | |
45 | , t_manual_map_result | |
8dad2faf | 46 | ], |
8bbf6f4d | 47 | Properties = [parallel], |
8dad2faf SK |
48 | [{?GROUP, Properties, Tests}]. |
49 | ||
2fa2f026 SK |
50 | %% ============================================================================= |
51 | %% Manual test cases | |
52 | %% ============================================================================= | |
53 | ||
54 | t_manual_map_result(_Cfg) -> | |
55 | AssertPositive = | |
56 | fun (I) when I > 0 -> {ok, I}; (_) -> {error, negative} end, | |
57 | AllPositives = lists:seq(1, 5), | |
58 | AllNegatives = lists:seq(-5, -1), | |
59 | Mixed = lists:seq(-5, 5), | |
60 | {ok, AllPositives} = hope_list:map_result(AllPositives, AssertPositive), | |
61 | {error, negative} = hope_list:map_result(AllNegatives, AssertPositive), | |
62 | {error, negative} = hope_list:map_result(Mixed, AssertPositive). | |
8dad2faf SK |
63 | |
64 | %% ============================================================================= | |
2fa2f026 | 65 | %% Generated test cases |
8dad2faf SK |
66 | %% ============================================================================= |
67 | ||
2fa2f026 | 68 | t_auto_map_rev(_Cfg) -> |
cf0f905c | 69 | ?CHECK(proper_spec_map_rev). |
c66ddf80 | 70 | |
2fa2f026 | 71 | t_auto_map_slow(_Cfg) -> |
cf0f905c | 72 | ?CHECK(proper_spec_map_slow). |
2a81fbac | 73 | |
2fa2f026 | 74 | t_auto_map(_Cfg) -> |
cf0f905c | 75 | ?CHECK(proper_spec_map). |
ff793acf | 76 | |
2fa2f026 | 77 | t_auto_map_3(_Cfg) -> |
cf0f905c | 78 | ?CHECK(proper_spec_map_3). |
fad0cddc | 79 | |
2fa2f026 | 80 | t_auto_unique_preserve_order(_Cfg) -> |
cf0f905c | 81 | ?CHECK(proper_spec_prop_unique_preserve_order). |
f4780d18 | 82 | |
2fa2f026 | 83 | t_auto_hope_list_specs(_Cfg) -> |
8bbf6f4d | 84 | [] = proper:check_specs(hope_list). |
54ab0c82 | 85 | |
cf0f905c SK |
86 | %% ============================================================================ |
87 | %% PropEr test specs | |
88 | %% ============================================================================ | |
89 | ||
90 | proper_spec_map_rev() -> | |
91 | ?FORALL({L, F}, {type_l(), type_f()}, | |
92 | hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L)) | |
93 | ). | |
94 | ||
95 | proper_spec_map_slow() -> | |
96 | ?FORALL({L, F}, {type_l(), type_f()}, | |
97 | hope_list:map_slow(L, F) == lists:map(F, L) | |
98 | ). | |
99 | ||
100 | proper_spec_map() -> | |
101 | ?FORALL({L, F}, {type_l(), type_f()}, | |
102 | hope_list:map(L, F) == lists:map(F, L) | |
103 | ). | |
104 | ||
105 | proper_spec_map_3() -> | |
106 | ?FORALL({L, F, N}, {type_l(), type_f(), ?type:non_neg_integer()}, | |
107 | hope_list:map(L, F, N) == lists:map(F, L) | |
108 | ). | |
109 | ||
110 | proper_spec_prop_unique_preserve_order() -> | |
111 | ?FORALL(L, ?type:list(), | |
112 | begin | |
113 | Duplicates = L -- lists:usort(L), | |
114 | hope_list:unique_preserve_order(L) == | |
115 | lists:reverse(lists:reverse(L) -- Duplicates) | |
116 | end). | |
117 | ||
118 | type_l() -> | |
119 | ?type:list(?type:integer()). | |
120 | ||
121 | type_f() -> | |
122 | ?type:function([?type:integer()], ?type:term()). |