| 1 | -module(hope_list_SUITE). |
| 2 | |
| 3 | -include_lib("proper/include/proper.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 | |
| 32 | all() -> |
| 33 | [{group, ?GROUP}]. |
| 34 | |
| 35 | groups() -> |
| 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 | |
| 53 | t_map_rev(_Cfg) -> |
| 54 | ?PROPTEST(map_rev). |
| 55 | |
| 56 | map_rev() -> |
| 57 | ?FORALL({L, F}, {list(integer()), function([integer()], term())}, |
| 58 | hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L))). |
| 59 | |
| 60 | t_map_slow(_Cfg) -> |
| 61 | ?PROPTEST(map_slow). |
| 62 | |
| 63 | map_slow() -> |
| 64 | ?FORALL({L, F}, {list(integer()), function([integer()], term())}, |
| 65 | hope_list:map_slow(L, F) == lists:map(F, L)). |
| 66 | |
| 67 | t_map(_Cfg) -> |
| 68 | ?PROPTEST(map). |
| 69 | |
| 70 | map() -> |
| 71 | ?FORALL({L, F}, {list(integer()), function([integer()], term())}, |
| 72 | hope_list:map(L, F) == lists:map(F, L)). |
| 73 | |
| 74 | t_map_3(_Cfg) -> |
| 75 | ?PROPTEST(map_3). |
| 76 | |
| 77 | map_3() -> |
| 78 | ?FORALL({L, F, N}, {list(integer()), function([integer()], term()), non_neg_integer()}, |
| 79 | hope_list:map(L, F, N) == lists:map(F, L)). |
| 80 | |
| 81 | t_unique_preserve_order(_Cfg) -> |
| 82 | ?PROPTEST(prop_unique_preserve_order). |
| 83 | |
| 84 | prop_unique_preserve_order() -> |
| 85 | ?FORALL(L, 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 | |
| 92 | t_hope_list_specs(_) -> |
| 93 | [] = proper:check_specs(hope_list). |
| 94 | |
| 95 | t_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). |