Implement a tail-recursive list map.
[hope.git] / test / hope_list_SUITE.erl
1 -module(hope_list_SUITE).
2
3 -include_lib("proper/include/proper.hrl").
4
5 %% Callbacks
6 -export(
7 [ all/0
8 , groups/0
9 ]).
10
11 %% Test cases
12 -export(
13 [ t_unique_preserve_order/1
14 , t_hope_list_specs/1
15 , t_map_rev/1
16 , t_map_slow/1
17 , t_map/1
18 ]).
19
20
21 -define(GROUP , hope_list).
22
23 -define(PROPTEST(A), true = proper:quickcheck(A())).
24
25
26 %% ============================================================================
27 %% Common Test callbacks
28 %% ============================================================================
29
30 all() ->
31 [{group, ?GROUP}].
32
33 groups() ->
34 Tests =
35 [ t_unique_preserve_order
36 , t_hope_list_specs
37 , t_map_rev
38 , t_map_slow
39 , t_map
40 ],
41 Properties = [parallel],
42 [{?GROUP, Properties, Tests}].
43
44
45 %% =============================================================================
46 %% Test cases
47 %% =============================================================================
48
49 t_map_rev(_Cfg) ->
50 F = fun (N) -> N + 1 end,
51 [4, 3, 2] = hope_list:map_rev([1, 2, 3], F),
52 [] = hope_list:map_rev([], F).
53
54 t_map_slow(_Cfg) ->
55 F = fun (N) -> N + 1 end,
56 [2, 3, 4] = hope_list:map_slow([1, 2, 3], F),
57 [] = hope_list:map_slow([], F).
58
59 t_map(_Cfg) ->
60 F = fun (N) -> N + 1 end,
61 Xs = lists:seq(1, 5010),
62 Ys = lists:map(F, Xs),
63 Ys = hope_list:map(Xs, F),
64 [] = hope_list:map([], F).
65
66 t_unique_preserve_order(_Cfg) ->
67 ?PROPTEST(prop_unique_preserve_order).
68
69 prop_unique_preserve_order() ->
70 ?FORALL(L, list(),
71 begin
72 Duplicates = L -- lists:usort(L),
73 hope_list:unique_preserve_order(L) ==
74 lists:reverse(lists:reverse(L) -- Duplicates)
75 end).
76
77 t_hope_list_specs(_) ->
78 [] = proper:check_specs(hope_list).
This page took 0.049303 seconds and 4 git commands to generate.