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
26 -define(GROUP , hope_list).
28 -define(TEST(TestSpec), true = proper:quickcheck(TestSpec)).
30 -define(type, proper_types).
33 %% ============================================================================
34 %% Common Test callbacks
35 %% ============================================================================
42 [ t_auto_hope_list_specs
47 , t_auto_unique_preserve_order
53 Properties = [parallel],
54 [{?GROUP, Properties, Tests}].
56 %% =============================================================================
58 %% =============================================================================
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).
67 t_manual_map_result(_Cfg) ->
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).
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).
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).
87 %% =============================================================================
88 %% Generated test cases
89 %% =============================================================================
91 t_auto_map_rev(_Cfg) ->
92 ?TEST(?FORALL({L, F}, {type_l(), type_f()},
93 hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L))
96 t_auto_map_slow(_Cfg) ->
97 ?TEST(?FORALL({L, F}, {type_l(), type_f()},
98 hope_list:map_slow(L, F) == lists:map(F, L)
102 ?TEST(?FORALL({L, F}, {type_l(), type_f()},
103 hope_list:map(L, F) == lists:map(F, L)
106 t_auto_map_3(_Cfg) ->
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)
111 t_auto_unique_preserve_order(_Cfg) ->
112 ?TEST(?FORALL(L, ?type:list(),
114 Duplicates = L -- lists:usort(L),
115 UniquesInOrderA = lists:reverse(lists:reverse(L) -- Duplicates),
116 UniquesInOrderB = hope_list:unique_preserve_order(L),
117 UniquesInOrderA == UniquesInOrderB
120 t_auto_hope_list_specs(_Cfg) ->
121 [] = proper:check_specs(hope_list).
123 %% ============================================================================
125 %% ============================================================================
128 ?type:list(?type:integer()).
131 ?type:function([?type:integer()], ?type:term()).