| 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_auto_hope_list_specs/1 |
| 14 | , t_auto_map/1 |
| 15 | , t_auto_map_3/1 |
| 16 | , t_auto_map_rev/1 |
| 17 | , t_auto_map_slow/1 |
| 18 | , t_auto_unique_preserve_order/1 |
| 19 | , t_manual_map_result/1 |
| 20 | ]). |
| 21 | |
| 22 | |
| 23 | -define(GROUP , hope_list). |
| 24 | |
| 25 | -define(CHECK(F), true = proper:quickcheck(F())). |
| 26 | |
| 27 | -define(type, proper_types). |
| 28 | |
| 29 | |
| 30 | %% ============================================================================ |
| 31 | %% Common Test callbacks |
| 32 | %% ============================================================================ |
| 33 | |
| 34 | all() -> |
| 35 | [{group, ?GROUP}]. |
| 36 | |
| 37 | groups() -> |
| 38 | Tests = |
| 39 | [ t_auto_hope_list_specs |
| 40 | , t_auto_map |
| 41 | , t_auto_map_3 |
| 42 | , t_auto_map_rev |
| 43 | , t_auto_map_slow |
| 44 | , t_auto_unique_preserve_order |
| 45 | , t_manual_map_result |
| 46 | ], |
| 47 | Properties = [parallel], |
| 48 | [{?GROUP, Properties, Tests}]. |
| 49 | |
| 50 | %% ============================================================================= |
| 51 | %% Manual test cases |
| 52 | %% ============================================================================= |
| 53 | |
| 54 | t_manual_map_result(_Cfg) -> |
| 55 | AssertPositive = |
| 56 | fun (I) when I > 0 -> {ok, I}; (_) -> {error, negative} end, |
| 57 | AllPositives = lists:seq(1, 5), |
| 58 | AllNegatives = lists:seq(-5, -1), |
| 59 | Mixed = lists:seq(-5, 5), |
| 60 | {ok, AllPositives} = hope_list:map_result(AllPositives, AssertPositive), |
| 61 | {error, negative} = hope_list:map_result(AllNegatives, AssertPositive), |
| 62 | {error, negative} = hope_list:map_result(Mixed, AssertPositive). |
| 63 | |
| 64 | %% ============================================================================= |
| 65 | %% Generated test cases |
| 66 | %% ============================================================================= |
| 67 | |
| 68 | t_auto_map_rev(_Cfg) -> |
| 69 | ?CHECK(proper_spec_map_rev). |
| 70 | |
| 71 | t_auto_map_slow(_Cfg) -> |
| 72 | ?CHECK(proper_spec_map_slow). |
| 73 | |
| 74 | t_auto_map(_Cfg) -> |
| 75 | ?CHECK(proper_spec_map). |
| 76 | |
| 77 | t_auto_map_3(_Cfg) -> |
| 78 | ?CHECK(proper_spec_map_3). |
| 79 | |
| 80 | t_auto_unique_preserve_order(_Cfg) -> |
| 81 | ?CHECK(proper_spec_prop_unique_preserve_order). |
| 82 | |
| 83 | t_auto_hope_list_specs(_Cfg) -> |
| 84 | [] = proper:check_specs(hope_list). |
| 85 | |
| 86 | %% ============================================================================ |
| 87 | %% PropEr test specs |
| 88 | %% ============================================================================ |
| 89 | |
| 90 | proper_spec_map_rev() -> |
| 91 | ?FORALL({L, F}, {type_l(), type_f()}, |
| 92 | hope_list:map_rev(L, F) == lists:reverse(lists:map(F, L)) |
| 93 | ). |
| 94 | |
| 95 | proper_spec_map_slow() -> |
| 96 | ?FORALL({L, F}, {type_l(), type_f()}, |
| 97 | hope_list:map_slow(L, F) == lists:map(F, L) |
| 98 | ). |
| 99 | |
| 100 | proper_spec_map() -> |
| 101 | ?FORALL({L, F}, {type_l(), type_f()}, |
| 102 | hope_list:map(L, F) == lists:map(F, L) |
| 103 | ). |
| 104 | |
| 105 | proper_spec_map_3() -> |
| 106 | ?FORALL({L, F, N}, {type_l(), type_f(), ?type:non_neg_integer()}, |
| 107 | hope_list:map(L, F, N) == lists:map(F, L) |
| 108 | ). |
| 109 | |
| 110 | proper_spec_prop_unique_preserve_order() -> |
| 111 | ?FORALL(L, ?type:list(), |
| 112 | begin |
| 113 | Duplicates = L -- lists:usort(L), |
| 114 | hope_list:unique_preserve_order(L) == |
| 115 | lists:reverse(lists:reverse(L) -- Duplicates) |
| 116 | end). |
| 117 | |
| 118 | type_l() -> |
| 119 | ?type:list(?type:integer()). |
| 120 | |
| 121 | type_f() -> |
| 122 | ?type:function([?type:integer()], ?type:term()). |