X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=test%2Fhope_kv_list_SUITE.erl;h=511fc32df383bb1ead117029c4ff296dcfc85ccd;hb=fa24061d65e74509ce66bbff0a6c99cbe33e9ddb;hp=97f0ee6bcc0bf6fc31733e585490b9dec44120f3;hpb=30a42d775b289fb111e5d80c7b35cfc9ef875a6b;p=hope.git diff --git a/test/hope_kv_list_SUITE.erl b/test/hope_kv_list_SUITE.erl index 97f0ee6..511fc32 100644 --- a/test/hope_kv_list_SUITE.erl +++ b/test/hope_kv_list_SUITE.erl @@ -8,63 +8,43 @@ %% Test cases -export( - [ t_set_new/1 - , t_set_existing/1 - , t_pop/1 + [ t_validate_unique_presence/1 ]). --define(GROUP_KV_LIST, kv_list). +-define(GROUP , hope_kv_list). %% ============================================================================ %% Common Test callbacks %% ============================================================================ -%% TODO: Make tests generic for any dictionary. -%% TODO: Each group should test a type of dictionary against the generic cases. - all() -> - [{group, ?GROUP_KV_LIST}]. + [{group, ?GROUP}]. groups() -> Tests = - [ t_set_new - , t_set_existing - , t_pop + [ t_validate_unique_presence ], Properties = [], - [{?GROUP_KV_LIST, Properties, Tests}]. + [{?GROUP, Properties, Tests}]. %% ============================================================================= %% Test cases %% ============================================================================= -t_set_new(_Config) -> - Key = key, - ValExpected = bar, - ListInitial = hope_kv_list:empty(), - ListResulting = hope_kv_list:set(ListInitial, Key, ValExpected), - {some, ValResulting} = hope_kv_list:get(ListResulting, Key), - ValResulting = ValExpected. - -t_set_existing(_Config) -> - Key = key, - ValInitial = foo, - ValExpected = bar, - ListInitial = [{donald, duck}, {Key, ValInitial}], - ListResulting = hope_kv_list:set(ListInitial, Key, ValExpected), - {some, ValResulting} = hope_kv_list:get(ListResulting, Key), - ValResulting = ValExpected. - -t_pop(_Config) -> - KVList = [{a, 1}, {b, 2}, {c, 3}], - Dict1 = hope_kv_list:of_kv_list(KVList), - {{some, 1} , Dict2} = hope_kv_list:pop(Dict1, a), - {none , Dict3} = hope_kv_list:pop(Dict2, a), - {{some, 2} , Dict4} = hope_kv_list:pop(Dict3, b), - {none , Dict5} = hope_kv_list:pop(Dict4, b), - {{some, 3} , Dict6} = hope_kv_list:pop(Dict5, c), - {none , Dict7} = hope_kv_list:pop(Dict6, c), - [] = hope_kv_list:to_kv_list(Dict7). +t_validate_unique_presence(_Cfg) -> + KeysRequired = [a, b, c], + DictOk = [{a, 1}, {b, 2}, {c, 3}], + DictUnsup = [{a, 1}, {b, 2}, {c, 3}, {d, 4}], + DictDups = [{a, 1}, {b, 2}, {c, 3}, {a, 4}], + DictMissing = [{a, 1}, {b, 2}], + {ok, ok} = + hope_kv_list:validate_unique_presence(DictOk, KeysRequired), + {error, [{keys_unsupported, [d]}]} = + hope_kv_list:validate_unique_presence(DictUnsup, KeysRequired), + {error, [{keys_duplicated, [a]}]} = + hope_kv_list:validate_unique_presence(DictDups, KeysRequired), + {error, [{keys_missing, [c]}]} = + hope_kv_list:validate_unique_presence(DictMissing, KeysRequired).