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 |
56b05e81 SK |
16 | ]). |
17 | ||
18 | ||
5e835f3e SK |
19 | -define(DICT_MODULE , dict_module). |
20 | -define(DICT_MODULE_KV_LIST , hope_kv_list). | |
56b05e81 SK |
21 | |
22 | ||
23 | %% ============================================================================ | |
24 | %% Common Test callbacks | |
25 | %% ============================================================================ | |
26 | ||
27 | all() -> | |
5e835f3e | 28 | [{group, ?DICT_MODULE_KV_LIST}]. |
56b05e81 SK |
29 | |
30 | groups() -> | |
31 | Tests = | |
39273fbe SK |
32 | [ t_set_new |
33 | , t_set_existing | |
70cf8e86 | 34 | , t_pop |
56b05e81 SK |
35 | ], |
36 | Properties = [], | |
5e835f3e SK |
37 | [{?DICT_MODULE_KV_LIST, Properties, Tests}]. |
38 | ||
39 | init_per_group(DictModule, Cfg) -> | |
40 | hope_kv_list:set(Cfg, ?DICT_MODULE, DictModule). | |
41 | ||
42 | end_per_group(_DictModule, _Cfg) -> | |
43 | ok. | |
56b05e81 SK |
44 | |
45 | ||
46 | %% ============================================================================= | |
47 | %% Test cases | |
48 | %% ============================================================================= | |
39273fbe | 49 | |
5e835f3e SK |
50 | t_set_new(Cfg) -> |
51 | {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE), | |
39273fbe SK |
52 | Key = key, |
53 | ValExpected = bar, | |
5e835f3e SK |
54 | ListInitial = DictModule:empty(), |
55 | ListResulting = DictModule:set(ListInitial, Key, ValExpected), | |
56 | {some, ValResulting} = DictModule:get(ListResulting, Key), | |
39273fbe SK |
57 | ValResulting = ValExpected. |
58 | ||
5e835f3e SK |
59 | t_set_existing(Cfg) -> |
60 | {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE), | |
39273fbe SK |
61 | Key = key, |
62 | ValInitial = foo, | |
63 | ValExpected = bar, | |
64 | ListInitial = [{donald, duck}, {Key, ValInitial}], | |
5e835f3e SK |
65 | ListResulting = DictModule:set(ListInitial, Key, ValExpected), |
66 | {some, ValResulting} = DictModule:get(ListResulting, Key), | |
39273fbe | 67 | ValResulting = ValExpected. |
70cf8e86 | 68 | |
5e835f3e SK |
69 | t_pop(Cfg) -> |
70 | {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE), | |
70cf8e86 | 71 | KVList = [{a, 1}, {b, 2}, {c, 3}], |
5e835f3e SK |
72 | Dict1 = DictModule:of_kv_list(KVList), |
73 | {{some, 1} , Dict2} = DictModule:pop(Dict1, a), | |
74 | {none , Dict3} = DictModule:pop(Dict2, a), | |
75 | {{some, 2} , Dict4} = DictModule:pop(Dict3, b), | |
76 | {none , Dict5} = DictModule:pop(Dict4, b), | |
77 | {{some, 3} , Dict6} = DictModule:pop(Dict5, c), | |
78 | {none , Dict7} = DictModule:pop(Dict6, c), | |
79 | [] = DictModule:to_kv_list(Dict7). |