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