Re-organize hope_list_SUITE
[hope.git] / test / hope_list_SUITE.erl
CommitLineData
8dad2faf
SK
1-module(hope_list_SUITE).
2
fd66fd0c 3-include_lib("proper/include/proper_common.hrl").
f4780d18 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
fad0cddc 18 , t_map_3/1
54ab0c82 19 , t_map_result/1
8dad2faf
SK
20 ]).
21
22
23-define(GROUP , hope_list).
24
cf0f905c 25-define(CHECK(F), true = proper:quickcheck(F())).
f4780d18 26
ea7f00f1
SK
27-define(type, proper_types).
28
8dad2faf
SK
29
30%% ============================================================================
31%% Common Test callbacks
32%% ============================================================================
33
34all() ->
35 [{group, ?GROUP}].
36
37groups() ->
38 Tests =
39 [ t_unique_preserve_order
8bbf6f4d 40 , t_hope_list_specs
c66ddf80 41 , t_map_rev
2a81fbac 42 , t_map_slow
ff793acf 43 , t_map
fad0cddc 44 , t_map_3
54ab0c82 45 , t_map_result
8dad2faf 46 ],
8bbf6f4d 47 Properties = [parallel],
8dad2faf
SK
48 [{?GROUP, Properties, Tests}].
49
50
51%% =============================================================================
52%% Test cases
53%% =============================================================================
54
c66ddf80 55t_map_rev(_Cfg) ->
cf0f905c 56 ?CHECK(proper_spec_map_rev).
c66ddf80 57
2a81fbac 58t_map_slow(_Cfg) ->
cf0f905c 59 ?CHECK(proper_spec_map_slow).
2a81fbac 60
ff793acf 61t_map(_Cfg) ->
cf0f905c 62 ?CHECK(proper_spec_map).
ff793acf 63
fad0cddc 64t_map_3(_Cfg) ->
cf0f905c 65 ?CHECK(proper_spec_map_3).
fad0cddc 66
8dad2faf 67t_unique_preserve_order(_Cfg) ->
cf0f905c 68 ?CHECK(proper_spec_prop_unique_preserve_order).
f4780d18 69
cf0f905c 70t_hope_list_specs(_Cfg) ->
8bbf6f4d 71 [] = proper:check_specs(hope_list).
54ab0c82
SK
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).
cf0f905c
SK
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.02578 seconds and 4 git commands to generate.