| 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 | ]). |
| 20 | |
| 21 | |
| 22 | -define(GROUP , hope_list). |
| 23 | |
| 24 | -define(PROPTEST(A), true = proper:quickcheck(A())). |
| 25 | |
| 26 | |
| 27 | %% ============================================================================ |
| 28 | %% Common Test callbacks |
| 29 | %% ============================================================================ |
| 30 | |
| 31 | all() -> |
| 32 | [{group, ?GROUP}]. |
| 33 | |
| 34 | groups() -> |
| 35 | Tests = |
| 36 | [ t_unique_preserve_order |
| 37 | , t_hope_list_specs |
| 38 | , t_map_rev |
| 39 | , t_map_slow |
| 40 | , t_map |
| 41 | , t_map_3 |
| 42 | ], |
| 43 | Properties = [parallel], |
| 44 | [{?GROUP, Properties, Tests}]. |
| 45 | |
| 46 | |
| 47 | %% ============================================================================= |
| 48 | %% Test cases |
| 49 | %% ============================================================================= |
| 50 | |
| 51 | t_map_rev(_Cfg) -> |
| 52 | ?PROPTEST(map_rev). |
| 53 | |
| 54 | map_rev() -> |
| 55 | ?FORALL({L, F}, {list(integer()), function([integer()], term())}, |
| 56 | hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L))). |
| 57 | |
| 58 | t_map_slow(_Cfg) -> |
| 59 | ?PROPTEST(map_slow). |
| 60 | |
| 61 | map_slow() -> |
| 62 | ?FORALL({L, F}, {list(integer()), function([integer()], term())}, |
| 63 | hope_list:map_slow(L, F) == lists:map(F, L)). |
| 64 | |
| 65 | t_map(_Cfg) -> |
| 66 | ?PROPTEST(map). |
| 67 | |
| 68 | map() -> |
| 69 | ?FORALL({L, F}, {list(integer()), function([integer()], term())}, |
| 70 | hope_list:map(L, F) == lists:map(F, L)). |
| 71 | |
| 72 | t_map_3(_Cfg) -> |
| 73 | ?PROPTEST(map_3). |
| 74 | |
| 75 | map_3() -> |
| 76 | ?FORALL({L, F, N}, {list(integer()), function([integer()], term()), non_neg_integer()}, |
| 77 | hope_list:map(L, F, N) == lists:map(F, L)). |
| 78 | |
| 79 | t_unique_preserve_order(_Cfg) -> |
| 80 | ?PROPTEST(prop_unique_preserve_order). |
| 81 | |
| 82 | prop_unique_preserve_order() -> |
| 83 | ?FORALL(L, list(), |
| 84 | begin |
| 85 | Duplicates = L -- lists:usort(L), |
| 86 | hope_list:unique_preserve_order(L) == |
| 87 | lists:reverse(lists:reverse(L) -- Duplicates) |
| 88 | end). |
| 89 | |
| 90 | t_hope_list_specs(_) -> |
| 91 | [] = proper:check_specs(hope_list). |