8994868bfe665d069e54b3a29cb2db82b107a9c2
[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_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 , t_map_3/1
19 , t_map_result/1
20 ]).
21
22
23 -define(GROUP , hope_list).
24
25 -define(PROPTEST(A), true = proper:quickcheck(A())).
26
27 -define(type, proper_types).
28
29
30 %% ============================================================================
31 %% Common Test callbacks
32 %% ============================================================================
33
34 all() ->
35 [{group, ?GROUP}].
36
37 groups() ->
38 Tests =
39 [ t_unique_preserve_order
40 , t_hope_list_specs
41 , t_map_rev
42 , t_map_slow
43 , t_map
44 , t_map_3
45 , t_map_result
46 ],
47 Properties = [parallel],
48 [{?GROUP, Properties, Tests}].
49
50
51 %% =============================================================================
52 %% Test cases
53 %% =============================================================================
54
55 t_map_rev(_Cfg) ->
56 ?PROPTEST(map_rev).
57
58 map_rev() ->
59 ?FORALL({L, F}, {?type:list(?type:integer()), ?type:function([?type:integer()], ?type:term())},
60 hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L))).
61
62 t_map_slow(_Cfg) ->
63 ?PROPTEST(map_slow).
64
65 map_slow() ->
66 ?FORALL({L, F}, {?type:list(?type:integer()), ?type:function([?type:integer()], ?type:term())},
67 hope_list:map_slow(L, F) == lists:map(F, L)).
68
69 t_map(_Cfg) ->
70 ?PROPTEST(map).
71
72 map() ->
73 ?FORALL({L, F}, {?type:list(?type:integer()), ?type:function([?type:integer()], ?type:term())},
74 hope_list:map(L, F) == lists:map(F, L)).
75
76 t_map_3(_Cfg) ->
77 ?PROPTEST(map_3).
78
79 map_3() ->
80 ?FORALL({L, F, N}, {?type:list(?type:integer()), ?type:function([?type:integer()], ?type:term()), ?type:non_neg_integer()},
81 hope_list:map(L, F, N) == lists:map(F, L)).
82
83 t_unique_preserve_order(_Cfg) ->
84 ?PROPTEST(prop_unique_preserve_order).
85
86 prop_unique_preserve_order() ->
87 ?FORALL(L, ?type:list(),
88 begin
89 Duplicates = L -- lists:usort(L),
90 hope_list:unique_preserve_order(L) ==
91 lists:reverse(lists:reverse(L) -- Duplicates)
92 end).
93
94 t_hope_list_specs(_) ->
95 [] = proper:check_specs(hope_list).
96
97 t_map_result(_Cfg) ->
98 AssertPositive =
99 fun (I) when I > 0 -> {ok, I}; (_) -> {error, negative} end,
100 AllPositives = lists:seq(1, 5),
101 AllNegatives = lists:seq(-5, -1),
102 Mixed = lists:seq(-5, 5),
103 {ok, AllPositives} = hope_list:map_result(AllPositives, AssertPositive),
104 {error, negative} = hope_list:map_result(AllNegatives, AssertPositive),
105 {error, negative} = hope_list:map_result(Mixed, AssertPositive).
This page took 0.073307 seconds and 3 git commands to generate.