X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=test%2Fhope_kv_list_SUITE.erl;h=b98603988ab3039847fde3c40abbc78df28a43b0;hb=99fd18ae3aa61238700208a5f2b2959c1b1a2d80;hp=e0f0747e2c7772862323939020e906da53269cad;hpb=a2673523b39fb6fbcc4fe4dce649f8a44c9fb94c;p=hope.git diff --git a/test/hope_kv_list_SUITE.erl b/test/hope_kv_list_SUITE.erl index e0f0747..b986039 100644 --- a/test/hope_kv_list_SUITE.erl +++ b/test/hope_kv_list_SUITE.erl @@ -1,5 +1,7 @@ -module(hope_kv_list_SUITE). +-include_lib("hope_kv_list.hrl"). + %% Callbacks -export( [ all/0 @@ -8,50 +10,71 @@ %% Test cases -export( - [ t_set_new/1 - , t_set_existing/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_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_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, DictOk} = + hope_kv_list:validate_unique_presence(DictOk, KeysRequired), + #hope_kv_list_presence_violations + { keys_missing = [] + , keys_duplicated = [] + , keys_unsupported = [] + } = + hope_kv_list:find_unique_presence_violations(DictOk, KeysRequired), + + {error, [{keys_unsupported, [d]}]} = + hope_kv_list:validate_unique_presence(DictUnsup, KeysRequired), + #hope_kv_list_presence_violations + { keys_missing = [] + , keys_duplicated = [] + , keys_unsupported = [d] + } = + hope_kv_list:find_unique_presence_violations(DictUnsup, KeysRequired), + + {error, [{keys_duplicated, [a]}]} = + hope_kv_list:validate_unique_presence(DictDups, KeysRequired), + #hope_kv_list_presence_violations + { keys_missing = [] + , keys_duplicated = [a] + , keys_unsupported = [] + } = + hope_kv_list:find_unique_presence_violations(DictDups, KeysRequired), + + {error, [{keys_missing, [c]}]} = + hope_kv_list:validate_unique_presence(DictMissing, KeysRequired), + #hope_kv_list_presence_violations + { keys_missing = [c] + , keys_duplicated = [] + , keys_unsupported = [] + } = + hope_kv_list:find_unique_presence_violations(DictMissing, KeysRequired).