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 | |
d302b4a3 | 19 | , t_manual_map/1 |
2fa2f026 | 20 | , t_manual_map_result/1 |
d302b4a3 SK |
21 | , t_manual_map_rev/1 |
22 | , t_manual_map_slow/1 | |
8dad2faf SK |
23 | ]). |
24 | ||
25 | ||
26 | -define(GROUP , hope_list). | |
27 | ||
cf0f905c | 28 | -define(CHECK(F), true = proper:quickcheck(F())). |
f4780d18 | 29 | |
ea7f00f1 SK |
30 | -define(type, proper_types). |
31 | ||
8dad2faf SK |
32 | |
33 | %% ============================================================================ | |
34 | %% Common Test callbacks | |
35 | %% ============================================================================ | |
36 | ||
37 | all() -> | |
38 | [{group, ?GROUP}]. | |
39 | ||
40 | groups() -> | |
41 | Tests = | |
2fa2f026 SK |
42 | [ t_auto_hope_list_specs |
43 | , t_auto_map | |
44 | , t_auto_map_3 | |
45 | , t_auto_map_rev | |
46 | , t_auto_map_slow | |
47 | , t_auto_unique_preserve_order | |
d302b4a3 | 48 | , t_manual_map |
2fa2f026 | 49 | , t_manual_map_result |
d302b4a3 SK |
50 | , t_manual_map_rev |
51 | , t_manual_map_slow | |
8dad2faf | 52 | ], |
8bbf6f4d | 53 | Properties = [parallel], |
8dad2faf SK |
54 | [{?GROUP, Properties, Tests}]. |
55 | ||
2fa2f026 SK |
56 | %% ============================================================================= |
57 | %% Manual test cases | |
58 | %% ============================================================================= | |
59 | ||
d302b4a3 SK |
60 | t_manual_map(_Cfg) -> |
61 | F = fun (N) -> N + 1 end, | |
62 | Xs = lists:seq(1, 5010), | |
63 | Ys = lists:map(F, Xs), | |
64 | Ys = hope_list:map(Xs, F), | |
65 | [] = hope_list:map([], F). | |
66 | ||
2fa2f026 SK |
67 | t_manual_map_result(_Cfg) -> |
68 | AssertPositive = | |
69 | fun (I) when I > 0 -> {ok, I}; (_) -> {error, negative} end, | |
70 | AllPositives = lists:seq(1, 5), | |
71 | AllNegatives = lists:seq(-5, -1), | |
72 | Mixed = lists:seq(-5, 5), | |
73 | {ok, AllPositives} = hope_list:map_result(AllPositives, AssertPositive), | |
74 | {error, negative} = hope_list:map_result(AllNegatives, AssertPositive), | |
75 | {error, negative} = hope_list:map_result(Mixed, AssertPositive). | |
8dad2faf | 76 | |
d302b4a3 SK |
77 | t_manual_map_rev(_Cfg) -> |
78 | F = fun (N) -> N + 1 end, | |
79 | [4, 3, 2] = hope_list:map_rev([1, 2, 3], F), | |
80 | [] = hope_list:map_rev([], F). | |
81 | ||
82 | t_manual_map_slow(_Cfg) -> | |
83 | F = fun (N) -> N + 1 end, | |
84 | [2, 3, 4] = hope_list:map_slow([1, 2, 3], F), | |
85 | [] = hope_list:map_slow([], F). | |
86 | ||
8dad2faf | 87 | %% ============================================================================= |
2fa2f026 | 88 | %% Generated test cases |
8dad2faf SK |
89 | %% ============================================================================= |
90 | ||
2fa2f026 | 91 | t_auto_map_rev(_Cfg) -> |
cf0f905c | 92 | ?CHECK(proper_spec_map_rev). |
c66ddf80 | 93 | |
2fa2f026 | 94 | t_auto_map_slow(_Cfg) -> |
cf0f905c | 95 | ?CHECK(proper_spec_map_slow). |
2a81fbac | 96 | |
2fa2f026 | 97 | t_auto_map(_Cfg) -> |
cf0f905c | 98 | ?CHECK(proper_spec_map). |
ff793acf | 99 | |
2fa2f026 | 100 | t_auto_map_3(_Cfg) -> |
cf0f905c | 101 | ?CHECK(proper_spec_map_3). |
fad0cddc | 102 | |
2fa2f026 | 103 | t_auto_unique_preserve_order(_Cfg) -> |
cf0f905c | 104 | ?CHECK(proper_spec_prop_unique_preserve_order). |
f4780d18 | 105 | |
2fa2f026 | 106 | t_auto_hope_list_specs(_Cfg) -> |
8bbf6f4d | 107 | [] = proper:check_specs(hope_list). |
54ab0c82 | 108 | |
cf0f905c SK |
109 | %% ============================================================================ |
110 | %% PropEr test specs | |
111 | %% ============================================================================ | |
112 | ||
113 | proper_spec_map_rev() -> | |
114 | ?FORALL({L, F}, {type_l(), type_f()}, | |
115 | hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L)) | |
116 | ). | |
117 | ||
118 | proper_spec_map_slow() -> | |
119 | ?FORALL({L, F}, {type_l(), type_f()}, | |
120 | hope_list:map_slow(L, F) == lists:map(F, L) | |
121 | ). | |
122 | ||
123 | proper_spec_map() -> | |
124 | ?FORALL({L, F}, {type_l(), type_f()}, | |
125 | hope_list:map(L, F) == lists:map(F, L) | |
126 | ). | |
127 | ||
128 | proper_spec_map_3() -> | |
129 | ?FORALL({L, F, N}, {type_l(), type_f(), ?type:non_neg_integer()}, | |
130 | hope_list:map(L, F, N) == lists:map(F, L) | |
131 | ). | |
132 | ||
133 | proper_spec_prop_unique_preserve_order() -> | |
134 | ?FORALL(L, ?type:list(), | |
135 | begin | |
136 | Duplicates = L -- lists:usort(L), | |
137 | hope_list:unique_preserve_order(L) == | |
138 | lists:reverse(lists:reverse(L) -- Duplicates) | |
139 | end). | |
140 | ||
141 | type_l() -> | |
142 | ?type:list(?type:integer()). | |
143 | ||
144 | type_f() -> | |
145 | ?type:function([?type:integer()], ?type:term()). |