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 | ||
dbe73b30 | 28 | -define(TEST(TestSpec), true = proper:quickcheck(TestSpec)). |
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) -> |
dbe73b30 SK |
92 | ?TEST(?FORALL({L, F}, {type_l(), type_f()}, |
93 | hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L)) | |
94 | )). | |
c66ddf80 | 95 | |
2fa2f026 | 96 | t_auto_map_slow(_Cfg) -> |
dbe73b30 SK |
97 | ?TEST(?FORALL({L, F}, {type_l(), type_f()}, |
98 | hope_list:map_slow(L, F) == lists:map(F, L) | |
99 | )). | |
2a81fbac | 100 | |
2fa2f026 | 101 | t_auto_map(_Cfg) -> |
dbe73b30 SK |
102 | ?TEST(?FORALL({L, F}, {type_l(), type_f()}, |
103 | hope_list:map(L, F) == lists:map(F, L) | |
104 | )). | |
ff793acf | 105 | |
2fa2f026 | 106 | t_auto_map_3(_Cfg) -> |
dbe73b30 SK |
107 | ?TEST(?FORALL({L, F, N}, {type_l(), type_f(), ?type:non_neg_integer()}, |
108 | hope_list:map(L, F, N) == lists:map(F, L) | |
109 | )). | |
fad0cddc | 110 | |
2fa2f026 | 111 | t_auto_unique_preserve_order(_Cfg) -> |
dbe73b30 SK |
112 | ?TEST(?FORALL(L, ?type:list(), |
113 | begin | |
114 | Duplicates = L -- lists:usort(L), | |
347e63e6 SK |
115 | UniquesInOrderA = lists:reverse(lists:reverse(L) -- Duplicates), |
116 | UniquesInOrderB = hope_list:unique_preserve_order(L), | |
117 | UniquesInOrderA == UniquesInOrderB | |
dbe73b30 | 118 | end)). |
f4780d18 | 119 | |
2fa2f026 | 120 | t_auto_hope_list_specs(_Cfg) -> |
8bbf6f4d | 121 | [] = proper:check_specs(hope_list). |
54ab0c82 | 122 | |
cf0f905c | 123 | %% ============================================================================ |
dbe73b30 | 124 | %% Common types |
cf0f905c SK |
125 | %% ============================================================================ |
126 | ||
cf0f905c SK |
127 | type_l() -> |
128 | ?type:list(?type:integer()). | |
129 | ||
130 | type_f() -> | |
131 | ?type:function([?type:integer()], ?type:term()). |