Bring-back manual test case for hope_list
[hope.git] / test / hope_list_SUITE.erl
1 -module(hope_list_SUITE).
2
3 -include_lib("proper/include/proper_common.hrl").
4
5 %% Callbacks
6 -export(
7 [ all/0
8 , groups/0
9 ]).
10
11 %% Test cases
12 -export(
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
19 , t_manual_map/1
20 , t_manual_map_result/1
21 , t_manual_map_rev/1
22 , t_manual_map_slow/1
23 ]).
24
25
26 -define(GROUP , hope_list).
27
28 -define(CHECK(F), true = proper:quickcheck(F())).
29
30 -define(type, proper_types).
31
32
33 %% ============================================================================
34 %% Common Test callbacks
35 %% ============================================================================
36
37 all() ->
38 [{group, ?GROUP}].
39
40 groups() ->
41 Tests =
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
48 , t_manual_map
49 , t_manual_map_result
50 , t_manual_map_rev
51 , t_manual_map_slow
52 ],
53 Properties = [parallel],
54 [{?GROUP, Properties, Tests}].
55
56 %% =============================================================================
57 %% Manual test cases
58 %% =============================================================================
59
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
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).
76
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
87 %% =============================================================================
88 %% Generated test cases
89 %% =============================================================================
90
91 t_auto_map_rev(_Cfg) ->
92 ?CHECK(proper_spec_map_rev).
93
94 t_auto_map_slow(_Cfg) ->
95 ?CHECK(proper_spec_map_slow).
96
97 t_auto_map(_Cfg) ->
98 ?CHECK(proper_spec_map).
99
100 t_auto_map_3(_Cfg) ->
101 ?CHECK(proper_spec_map_3).
102
103 t_auto_unique_preserve_order(_Cfg) ->
104 ?CHECK(proper_spec_prop_unique_preserve_order).
105
106 t_auto_hope_list_specs(_Cfg) ->
107 [] = proper:check_specs(hope_list).
108
109 %% ============================================================================
110 %% PropEr test specs
111 %% ============================================================================
112
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))
116 ).
117
118 proper_spec_map_slow() ->
119 ?FORALL({L, F}, {type_l(), type_f()},
120 hope_list:map_slow(L, F) == lists:map(F, L)
121 ).
122
123 proper_spec_map() ->
124 ?FORALL({L, F}, {type_l(), type_f()},
125 hope_list:map(L, F) == lists:map(F, L)
126 ).
127
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)
131 ).
132
133 proper_spec_prop_unique_preserve_order() ->
134 ?FORALL(L, ?type:list(),
135 begin
136 Duplicates = L -- lists:usort(L),
137 hope_list:unique_preserve_order(L) ==
138 lists:reverse(lists:reverse(L) -- Duplicates)
139 end).
140
141 type_l() ->
142 ?type:list(?type:integer()).
143
144 type_f() ->
145 ?type:function([?type:integer()], ?type:term()).
This page took 0.060702 seconds and 4 git commands to generate.