Commit | Line | Data |
---|---|---|
f399d3fc | 1 | -module(hope_dictionary_SUITE). |
56b05e81 SK |
2 | |
3 | %% Callbacks | |
4 | -export( | |
5 | [ all/0 | |
6 | , groups/0 | |
5e835f3e SK |
7 | , init_per_group/2 |
8 | , end_per_group/2 | |
56b05e81 SK |
9 | ]). |
10 | ||
11 | %% Test cases | |
12 | -export( | |
39273fbe SK |
13 | [ t_set_new/1 |
14 | , t_set_existing/1 | |
70cf8e86 | 15 | , t_pop/1 |
e75cf601 | 16 | , t_fold/1 |
56b05e81 SK |
17 | ]). |
18 | ||
19 | ||
5e835f3e SK |
20 | -define(DICT_MODULE , dict_module). |
21 | -define(DICT_MODULE_KV_LIST , hope_kv_list). | |
56b05e81 SK |
22 | |
23 | ||
24 | %% ============================================================================ | |
25 | %% Common Test callbacks | |
26 | %% ============================================================================ | |
27 | ||
28 | all() -> | |
5e835f3e | 29 | [{group, ?DICT_MODULE_KV_LIST}]. |
56b05e81 SK |
30 | |
31 | groups() -> | |
32 | Tests = | |
39273fbe SK |
33 | [ t_set_new |
34 | , t_set_existing | |
70cf8e86 | 35 | , t_pop |
e75cf601 | 36 | , t_fold |
56b05e81 SK |
37 | ], |
38 | Properties = [], | |
5e835f3e SK |
39 | [{?DICT_MODULE_KV_LIST, Properties, Tests}]. |
40 | ||
41 | init_per_group(DictModule, Cfg) -> | |
42 | hope_kv_list:set(Cfg, ?DICT_MODULE, DictModule). | |
43 | ||
44 | end_per_group(_DictModule, _Cfg) -> | |
45 | ok. | |
56b05e81 SK |
46 | |
47 | ||
48 | %% ============================================================================= | |
49 | %% Test cases | |
50 | %% ============================================================================= | |
39273fbe | 51 | |
5e835f3e SK |
52 | t_set_new(Cfg) -> |
53 | {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE), | |
39273fbe SK |
54 | Key = key, |
55 | ValExpected = bar, | |
5e835f3e SK |
56 | ListInitial = DictModule:empty(), |
57 | ListResulting = DictModule:set(ListInitial, Key, ValExpected), | |
58 | {some, ValResulting} = DictModule:get(ListResulting, Key), | |
39273fbe SK |
59 | ValResulting = ValExpected. |
60 | ||
5e835f3e SK |
61 | t_set_existing(Cfg) -> |
62 | {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE), | |
39273fbe SK |
63 | Key = key, |
64 | ValInitial = foo, | |
65 | ValExpected = bar, | |
66 | ListInitial = [{donald, duck}, {Key, ValInitial}], | |
5e835f3e SK |
67 | ListResulting = DictModule:set(ListInitial, Key, ValExpected), |
68 | {some, ValResulting} = DictModule:get(ListResulting, Key), | |
39273fbe | 69 | ValResulting = ValExpected. |
70cf8e86 | 70 | |
5e835f3e SK |
71 | t_pop(Cfg) -> |
72 | {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE), | |
70cf8e86 | 73 | KVList = [{a, 1}, {b, 2}, {c, 3}], |
5e835f3e SK |
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). | |
e75cf601 SK |
82 | |
83 | t_fold(Cfg) -> | |
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). |