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