1 -module(hope_dictionary_SUITE).
3 -include_lib("proper/include/proper.hrl").
19 , t_dictionary_specs/1
23 -define(DICT_MODULE , dict_module).
24 -define(DICT_MODULE_KV_LIST , hope_kv_list).
27 %% ============================================================================
28 %% Common Test callbacks
29 %% ============================================================================
32 [{group, ?DICT_MODULE_KV_LIST}].
42 Properties = [parallel],
43 [{?DICT_MODULE_KV_LIST, Properties, Tests}].
45 init_per_group(DictModule, Cfg) ->
46 hope_kv_list:set(Cfg, ?DICT_MODULE, DictModule).
48 end_per_group(_DictModule, _Cfg) ->
52 %% =============================================================================
54 %% =============================================================================
57 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
60 ListInitial = DictModule:empty(),
61 ListResulting = DictModule:set(ListInitial, Key, ValExpected),
62 {some, ValResulting} = DictModule:get(ListResulting, Key),
63 ValResulting = ValExpected.
65 t_set_existing(Cfg) ->
66 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
70 ListInitial = [{donald, duck}, {Key, ValInitial}],
71 ListResulting = DictModule:set(ListInitial, Key, ValExpected),
72 {some, ValResulting} = DictModule:get(ListResulting, Key),
73 ValResulting = ValExpected.
76 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
77 KVList = [{a, 1}, {b, 2}, {c, 3}],
78 Dict1 = DictModule:of_kv_list(KVList),
79 {{some, 1} , Dict2} = DictModule:pop(Dict1, a),
80 {none , Dict3} = DictModule:pop(Dict2, a),
81 {{some, 2} , Dict4} = DictModule:pop(Dict3, b),
82 {none , Dict5} = DictModule:pop(Dict4, b),
83 {{some, 3} , Dict6} = DictModule:pop(Dict5, c),
84 {none , Dict7} = DictModule:pop(Dict6, c),
85 [] = DictModule:to_kv_list(Dict7).
88 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
89 KVList = [{a, 1}, {a, 5}, {b, 3}, {c, 4}, {c, 4}],
90 Dict = DictModule:of_kv_list(KVList),
91 17 = DictModule:fold(Dict, fun (_K, V, Acc) -> V + Acc end, 0).
93 t_dictionary_specs(Cfg) ->
94 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
95 [] = proper:check_specs(DictModule).