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(CHECK(F), true = proper:quickcheck(F())).
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 ?CHECK(proper_spec_map_rev).
94 t_auto_map_slow(_Cfg) ->
95 ?CHECK(proper_spec_map_slow).
98 ?CHECK(proper_spec_map).
100 t_auto_map_3(_Cfg) ->
101 ?CHECK(proper_spec_map_3).
103 t_auto_unique_preserve_order(_Cfg) ->
104 ?CHECK(proper_spec_prop_unique_preserve_order).
106 t_auto_hope_list_specs(_Cfg) ->
107 [] = proper:check_specs(hope_list).
109 %% ============================================================================
111 %% ============================================================================
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))
118 proper_spec_map_slow() ->
119 ?FORALL({L, F}, {type_l(), type_f()},
120 hope_list:map_slow(L, F) == lists:map(F, L)
124 ?FORALL({L, F}, {type_l(), type_f()},
125 hope_list:map(L, F) == lists:map(F, L)
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)
133 proper_spec_prop_unique_preserve_order() ->
134 ?FORALL(L, ?type:list(),
136 Duplicates = L -- lists:usort(L),
137 hope_list:unique_preserve_order(L) ==
138 lists:reverse(lists:reverse(L) -- Duplicates)
142 ?type:list(?type:integer()).
145 ?type:function([?type:integer()], ?type:term()).