1 -module(hope_list_SUITE).
3 -include_lib("proper/include/proper_common.hrl").
13 [ t_auto_hope_list_specs/1
18 , t_auto_unique_preserve_order/1
20 , t_manual_map_result/1
27 -define(GROUP , hope_list).
29 -define(TEST(TestSpec), true = proper:quickcheck(TestSpec)).
31 -define(type, proper_types).
34 %% ============================================================================
35 %% Common Test callbacks
36 %% ============================================================================
43 [ t_auto_hope_list_specs
48 , t_auto_unique_preserve_order
55 Properties = [parallel],
56 [{?GROUP, Properties, Tests}].
58 %% =============================================================================
60 %% =============================================================================
63 F = fun (N) -> N + 1 end,
64 Xs = lists:seq(1, 5010),
65 Ys = lists:map(F, Xs),
66 Ys = hope_list:map(Xs, F),
67 [] = hope_list:map([], F).
69 t_manual_map_result(_Cfg) ->
71 fun (I) when I > 0 -> {ok, I}; (_) -> {error, negative} end,
72 AllPositives = lists:seq(1, 5),
73 AllNegatives = lists:seq(-5, -1),
74 Mixed = lists:seq(-5, 5),
75 {ok, AllPositives} = hope_list:map_result(AllPositives, AssertPositive),
76 {error, negative} = hope_list:map_result(AllNegatives, AssertPositive),
77 {error, negative} = hope_list:map_result(Mixed, AssertPositive).
79 t_manual_map_rev(_Cfg) ->
80 F = fun (N) -> N + 1 end,
81 [4, 3, 2] = hope_list:map_rev([1, 2, 3], F),
82 [] = hope_list:map_rev([], F).
84 t_manual_map_slow(_Cfg) ->
85 F = fun (N) -> N + 1 end,
86 [2, 3, 4] = hope_list:map_slow([1, 2, 3], F),
87 [] = hope_list:map_slow([], F).
89 t_manual_divide(_Cfg) ->
91 hope_list:divide([a, b, c], -1)
93 error:hope_list__divide__size_must_be_a_positive_integer -> ok
96 hope_list:divide([a, b, c], 0)
98 error:hope_list__divide__size_must_be_a_positive_integer -> ok
100 [[c], [b], [a]] = hope_list:divide([a, b, c], 1),
101 [[c], [b, a]] = hope_list:divide([a, b, c], 2),
102 [[c, b, a]] = hope_list:divide([a, b, c], 3),
103 [[c, b, a]] = hope_list:divide([a, b, c], 4),
104 [[c, b, a]] = hope_list:divide([a, b, c], 5),
106 hope_list:divide([], 0)
108 error:hope_list__divide__size_must_be_a_positive_integer -> ok
111 hope_list:divide([], -1)
113 error:hope_list__divide__size_must_be_a_positive_integer -> ok
115 [[f, e], [d, c], [b, a]] = hope_list:divide([a, b, c, d, e, f], 2),
116 [[f, e, d], [c, b, a]] = hope_list:divide([a, b, c, d, e, f], 3).
118 %% =============================================================================
119 %% Generated test cases
120 %% =============================================================================
122 t_auto_map_rev(_Cfg) ->
123 ?TEST(?FORALL({L, F}, {type_l(), type_f()},
124 hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L))
127 t_auto_map_slow(_Cfg) ->
128 ?TEST(?FORALL({L, F}, {type_l(), type_f()},
129 hope_list:map_slow(L, F) == lists:map(F, L)
133 ?TEST(?FORALL({L, F}, {type_l(), type_f()},
134 hope_list:map(L, F) == lists:map(F, L)
137 t_auto_map_3(_Cfg) ->
138 ?TEST(?FORALL({L, F, N}, {type_l(), type_f(), ?type:non_neg_integer()},
139 hope_list:map(L, F, N) == lists:map(F, L)
142 t_auto_unique_preserve_order(_Cfg) ->
143 ?TEST(?FORALL(L, ?type:list(),
145 Duplicates = L -- lists:usort(L),
146 UniquesInOrderA = lists:reverse(lists:reverse(L) -- Duplicates),
147 UniquesInOrderB = hope_list:unique_preserve_order(L),
148 UniquesInOrderA == UniquesInOrderB
151 t_auto_hope_list_specs(_Cfg) ->
152 [] = proper:check_specs(hope_list).
154 %% ============================================================================
156 %% ============================================================================
159 ?type:list(?type:integer()).
162 ?type:function([?type:integer()], ?type:term()).