X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=test%2Fhope_dictionary_SUITE.erl;h=cf0bfba6afec5fe9a22249c558eb779acefc5727;hb=HEAD;hp=f6a3e387539ed06f5787a64c9cc7613191f23765;hpb=e75cf6013e87c8a1952b2c22dad9b4796014f6e7;p=hope.git diff --git a/test/hope_dictionary_SUITE.erl b/test/hope_dictionary_SUITE.erl index f6a3e38..cf0bfba 100644 --- a/test/hope_dictionary_SUITE.erl +++ b/test/hope_dictionary_SUITE.erl @@ -12,8 +12,11 @@ -export( [ t_set_new/1 , t_set_existing/1 + , t_get/1 , t_pop/1 , t_fold/1 + , t_dictionary_specs/1 + , t_has_key/1 ]). @@ -32,10 +35,13 @@ groups() -> Tests = [ t_set_new , t_set_existing + , t_get , t_pop , t_fold + , t_dictionary_specs + , t_has_key ], - Properties = [], + Properties = [parallel], [{?DICT_MODULE_KV_LIST, Properties, Tests}]. init_per_group(DictModule, Cfg) -> @@ -49,6 +55,20 @@ end_per_group(_DictModule, _Cfg) -> %% Test cases %% ============================================================================= +t_get(Cfg) -> + {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE), + K1 = k1, + K2 = k2, + V1 = v1, + V2 = v2, + D = DictModule:set(DictModule:empty(), K1, V1), + {some, V1} = DictModule:get(D, K1), + V1 = DictModule:get(D, K1, V2), + none = DictModule:get(D, K2), + V2 = DictModule:get(D, K2, V2), + default = DictModule:get(D, K1, default, fun (X) -> X =:= foo end), + V1 = DictModule:get(D, K1, default, fun (X) -> X =:= V1 end). + t_set_new(Cfg) -> {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE), Key = key, @@ -85,3 +105,17 @@ t_fold(Cfg) -> KVList = [{a, 1}, {a, 5}, {b, 3}, {c, 4}, {c, 4}], Dict = DictModule:of_kv_list(KVList), 17 = DictModule:fold(Dict, fun (_K, V, Acc) -> V + Acc end, 0). + +t_dictionary_specs(Cfg) -> + {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE), + [] = proper:check_specs(DictModule). + +t_has_key(Cfg) -> + {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE), + D = DictModule:of_kv_list([{a, 1}, {b, 2}, {c, 3}]), + true = DictModule:has_key(D, a), + true = DictModule:has_key(D, b), + true = DictModule:has_key(D, c), + false = DictModule:has_key(D, d), + false = DictModule:has_key(D, e), + false = DictModule:has_key(D, f).