1 -module(hope_dictionary_SUITE).
20 -define(DICT_MODULE , dict_module).
21 -define(DICT_MODULE_KV_LIST , hope_kv_list).
24 %% ============================================================================
25 %% Common Test callbacks
26 %% ============================================================================
29 [{group, ?DICT_MODULE_KV_LIST}].
39 [{?DICT_MODULE_KV_LIST, Properties, Tests}].
41 init_per_group(DictModule, Cfg) ->
42 hope_kv_list:set(Cfg, ?DICT_MODULE, DictModule).
44 end_per_group(_DictModule, _Cfg) ->
48 %% =============================================================================
50 %% =============================================================================
53 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
56 ListInitial = DictModule:empty(),
57 ListResulting = DictModule:set(ListInitial, Key, ValExpected),
58 {some, ValResulting} = DictModule:get(ListResulting, Key),
59 ValResulting = ValExpected.
61 t_set_existing(Cfg) ->
62 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
66 ListInitial = [{donald, duck}, {Key, ValInitial}],
67 ListResulting = DictModule:set(ListInitial, Key, ValExpected),
68 {some, ValResulting} = DictModule:get(ListResulting, Key),
69 ValResulting = ValExpected.
72 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
73 KVList = [{a, 1}, {b, 2}, {c, 3}],
74 Dict1 = DictModule:of_kv_list(KVList),
75 {{some, 1} , Dict2} = DictModule:pop(Dict1, a),
76 {none , Dict3} = DictModule:pop(Dict2, a),
77 {{some, 2} , Dict4} = DictModule:pop(Dict3, b),
78 {none , Dict5} = DictModule:pop(Dict4, b),
79 {{some, 3} , Dict6} = DictModule:pop(Dict5, c),
80 {none , Dict7} = DictModule:pop(Dict6, c),
81 [] = DictModule:to_kv_list(Dict7).
84 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
85 KVList = [{a, 1}, {a, 5}, {b, 3}, {c, 4}, {c, 4}],
86 Dict = DictModule:of_kv_list(KVList),
87 17 = DictModule:fold(Dict, fun (_K, V, Acc) -> V + Acc end, 0).