Use property tests for map, map_rev and map_slow
[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 49t_map_rev(_Cfg) ->
886a9557
PO
50 ?PROPTEST(map_rev).
51
52map_rev() ->
53 ?FORALL({L, F}, {list(integer()), function([integer()], term())},
54 hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L))).
c66ddf80 55
2a81fbac 56t_map_slow(_Cfg) ->
886a9557
PO
57 ?PROPTEST(map_slow).
58
59map_slow() ->
60 ?FORALL({L, F}, {list(integer()), function([integer()], term())},
61 hope_list:map_slow(L, F) == lists:map(F, L)).
2a81fbac 62
ff793acf 63t_map(_Cfg) ->
886a9557
PO
64 ?PROPTEST(map).
65
66map() ->
67 ?FORALL({L, F}, {list(integer()), function([integer()], term())},
68 hope_list:map(L, F) == lists:map(F, L)).
ff793acf 69
8dad2faf 70t_unique_preserve_order(_Cfg) ->
f4780d18
PO
71 ?PROPTEST(prop_unique_preserve_order).
72
73prop_unique_preserve_order() ->
74 ?FORALL(L, list(),
75 begin
76 Duplicates = L -- lists:usort(L),
77 hope_list:unique_preserve_order(L) ==
78 lists:reverse(lists:reverse(L) -- Duplicates)
79 end).
8bbf6f4d
PO
80
81t_hope_list_specs(_) ->
82 [] = proper:check_specs(hope_list).
This page took 0.038093 seconds and 4 git commands to generate.