Implement a tail-recursive list map.
[hope.git] / test / hope_list_SUITE.erl
CommitLineData
8dad2faf
SK
1-module(hope_list_SUITE).
2
f4780d18
PO
3-include_lib("proper/include/proper.hrl").
4
8dad2faf
SK
5%% Callbacks
6-export(
7 [ all/0
8 , groups/0
9 ]).
10
11%% Test cases
12-export(
13 [ t_unique_preserve_order/1
8bbf6f4d 14 , t_hope_list_specs/1
c66ddf80 15 , t_map_rev/1
2a81fbac 16 , t_map_slow/1
ff793acf 17 , t_map/1
8dad2faf
SK
18 ]).
19
20
21-define(GROUP , hope_list).
22
f4780d18
PO
23-define(PROPTEST(A), true = proper:quickcheck(A())).
24
8dad2faf
SK
25
26%% ============================================================================
27%% Common Test callbacks
28%% ============================================================================
29
30all() ->
31 [{group, ?GROUP}].
32
33groups() ->
34 Tests =
35 [ t_unique_preserve_order
8bbf6f4d 36 , t_hope_list_specs
c66ddf80 37 , t_map_rev
2a81fbac 38 , t_map_slow
ff793acf 39 , t_map
8dad2faf 40 ],
8bbf6f4d 41 Properties = [parallel],
8dad2faf
SK
42 [{?GROUP, Properties, Tests}].
43
44
45%% =============================================================================
46%% Test cases
47%% =============================================================================
48
c66ddf80
SK
49t_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
2a81fbac
SK
54t_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
ff793acf
SK
59t_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
8dad2faf 66t_unique_preserve_order(_Cfg) ->
f4780d18
PO
67 ?PROPTEST(prop_unique_preserve_order).
68
69prop_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).
8bbf6f4d
PO
76
77t_hope_list_specs(_) ->
78 [] = proper:check_specs(hope_list).
This page took 0.02341 seconds and 4 git commands to generate.