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