Re-organize hope_list_SUITE
[hope.git] / test / hope_list_SUITE.erl
... / ...
CommitLineData
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(CHECK(F), true = proper:quickcheck(F())).
26
27-define(type, proper_types).
28
29
30%% ============================================================================
31%% Common Test callbacks
32%% ============================================================================
33
34all() ->
35 [{group, ?GROUP}].
36
37groups() ->
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
55t_map_rev(_Cfg) ->
56 ?CHECK(proper_spec_map_rev).
57
58t_map_slow(_Cfg) ->
59 ?CHECK(proper_spec_map_slow).
60
61t_map(_Cfg) ->
62 ?CHECK(proper_spec_map).
63
64t_map_3(_Cfg) ->
65 ?CHECK(proper_spec_map_3).
66
67t_unique_preserve_order(_Cfg) ->
68 ?CHECK(proper_spec_prop_unique_preserve_order).
69
70t_hope_list_specs(_Cfg) ->
71 [] = proper:check_specs(hope_list).
72
73t_map_result(_Cfg) ->
74 AssertPositive =
75 fun (I) when I > 0 -> {ok, I}; (_) -> {error, negative} end,
76 AllPositives = lists:seq(1, 5),
77 AllNegatives = lists:seq(-5, -1),
78 Mixed = lists:seq(-5, 5),
79 {ok, AllPositives} = hope_list:map_result(AllPositives, AssertPositive),
80 {error, negative} = hope_list:map_result(AllNegatives, AssertPositive),
81 {error, negative} = hope_list:map_result(Mixed, AssertPositive).
82
83%% ============================================================================
84%% PropEr test specs
85%% ============================================================================
86
87proper_spec_map_rev() ->
88 ?FORALL({L, F}, {type_l(), type_f()},
89 hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L))
90 ).
91
92proper_spec_map_slow() ->
93 ?FORALL({L, F}, {type_l(), type_f()},
94 hope_list:map_slow(L, F) == lists:map(F, L)
95 ).
96
97proper_spec_map() ->
98 ?FORALL({L, F}, {type_l(), type_f()},
99 hope_list:map(L, F) == lists:map(F, L)
100 ).
101
102proper_spec_map_3() ->
103 ?FORALL({L, F, N}, {type_l(), type_f(), ?type:non_neg_integer()},
104 hope_list:map(L, F, N) == lists:map(F, L)
105 ).
106
107proper_spec_prop_unique_preserve_order() ->
108 ?FORALL(L, ?type:list(),
109 begin
110 Duplicates = L -- lists:usort(L),
111 hope_list:unique_preserve_order(L) ==
112 lists:reverse(lists:reverse(L) -- Duplicates)
113 end).
114
115type_l() ->
116 ?type:list(?type:integer()).
117
118type_f() ->
119 ?type:function([?type:integer()], ?type:term()).
This page took 0.022754 seconds and 4 git commands to generate.