1 -module(hope_dictionary_SUITE).
18 , t_dictionary_specs/1
22 -define(DICT_MODULE , dict_module).
23 -define(DICT_MODULE_KV_LIST , hope_kv_list).
26 %% ============================================================================
27 %% Common Test callbacks
28 %% ============================================================================
31 [{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),
62 D = DictModule:set(DictModule:empty(), K1, V1),
63 {some, V1} = DictModule:get(D, K1),
64 V1 = DictModule:get(D, K1, V2),
65 none = DictModule:get(D, K2),
66 V2 = DictModule:get(D, K2, V2),
67 default = DictModule:get(D, K1, default, fun (X) -> X =:= foo end),
68 V1 = DictModule:get(D, K1, default, fun (X) -> X =:= V1 end).
71 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
74 ListInitial = DictModule:empty(),
75 ListResulting = DictModule:set(ListInitial, Key, ValExpected),
76 {some, ValResulting} = DictModule:get(ListResulting, Key),
77 ValResulting = ValExpected.
79 t_set_existing(Cfg) ->
80 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
84 ListInitial = [{donald, duck}, {Key, ValInitial}],
85 ListResulting = DictModule:set(ListInitial, Key, ValExpected),
86 {some, ValResulting} = DictModule:get(ListResulting, Key),
87 ValResulting = ValExpected.
90 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
91 KVList = [{a, 1}, {b, 2}, {c, 3}],
92 Dict1 = DictModule:of_kv_list(KVList),
93 {{some, 1} , Dict2} = DictModule:pop(Dict1, a),
94 {none , Dict3} = DictModule:pop(Dict2, a),
95 {{some, 2} , Dict4} = DictModule:pop(Dict3, b),
96 {none , Dict5} = DictModule:pop(Dict4, b),
97 {{some, 3} , Dict6} = DictModule:pop(Dict5, c),
98 {none , Dict7} = DictModule:pop(Dict6, c),
99 [] = DictModule:to_kv_list(Dict7).
102 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
103 KVList = [{a, 1}, {a, 5}, {b, 3}, {c, 4}, {c, 4}],
104 Dict = DictModule:of_kv_list(KVList),
105 17 = DictModule:fold(Dict, fun (_K, V, Acc) -> V + Acc end, 0).
107 t_dictionary_specs(Cfg) ->
108 {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
109 [] = proper:check_specs(DictModule).