Add dictionary method: pop.
[hope.git] / test / hope_kv_list_SUITE.erl
1 -module(hope_kv_list_SUITE).
2
3 %% Callbacks
4 -export(
5 [ all/0
6 , groups/0
7 ]).
8
9 %% Test cases
10 -export(
11 [ t_set_new/1
12 , t_set_existing/1
13 , t_pop/1
14 ]).
15
16
17 -define(GROUP_KV_LIST, kv_list).
18
19
20 %% ============================================================================
21 %% Common Test callbacks
22 %% ============================================================================
23
24 %% TODO: Make tests generic for any dictionary.
25 %% TODO: Each group should test a type of dictionary against the generic cases.
26
27 all() ->
28 [{group, ?GROUP_KV_LIST}].
29
30 groups() ->
31 Tests =
32 [ t_set_new
33 , t_set_existing
34 , t_pop
35 ],
36 Properties = [],
37 [{?GROUP_KV_LIST, Properties, Tests}].
38
39
40 %% =============================================================================
41 %% Test cases
42 %% =============================================================================
43
44 t_set_new(_Config) ->
45 Key = key,
46 ValExpected = bar,
47 ListInitial = hope_kv_list:empty(),
48 ListResulting = hope_kv_list:set(ListInitial, Key, ValExpected),
49 {some, ValResulting} = hope_kv_list:get(ListResulting, Key),
50 ValResulting = ValExpected.
51
52 t_set_existing(_Config) ->
53 Key = key,
54 ValInitial = foo,
55 ValExpected = bar,
56 ListInitial = [{donald, duck}, {Key, ValInitial}],
57 ListResulting = hope_kv_list:set(ListInitial, Key, ValExpected),
58 {some, ValResulting} = hope_kv_list:get(ListResulting, Key),
59 ValResulting = ValExpected.
60
61 t_pop(_Config) ->
62 KVList = [{a, 1}, {b, 2}, {c, 3}],
63 Dict1 = hope_kv_list:of_kv_list(KVList),
64 {{some, 1}, Dict2} = hope_kv_list:pop(Dict1, a),
65 {none , _Dict3} = hope_kv_list:pop(Dict2, a).
This page took 0.052935 seconds and 4 git commands to generate.