Add dictionary method: pop.
[hope.git] / test / hope_kv_list_SUITE.erl
CommitLineData
56b05e81
SK
1-module(hope_kv_list_SUITE).
2
3%% Callbacks
4-export(
5 [ all/0
6 , groups/0
7 ]).
8
9%% Test cases
10-export(
39273fbe
SK
11 [ t_set_new/1
12 , t_set_existing/1
70cf8e86 13 , t_pop/1
56b05e81
SK
14 ]).
15
16
17-define(GROUP_KV_LIST, kv_list).
18
19
20%% ============================================================================
21%% Common Test callbacks
22%% ============================================================================
23
37c6e98b 24%% TODO: Make tests generic for any dictionary.
a2673523 25%% TODO: Each group should test a type of dictionary against the generic cases.
37c6e98b 26
56b05e81
SK
27all() ->
28 [{group, ?GROUP_KV_LIST}].
29
30groups() ->
31 Tests =
39273fbe
SK
32 [ t_set_new
33 , t_set_existing
70cf8e86 34 , t_pop
56b05e81
SK
35 ],
36 Properties = [],
37 [{?GROUP_KV_LIST, Properties, Tests}].
38
39
40%% =============================================================================
41%% Test cases
42%% =============================================================================
39273fbe
SK
43
44t_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
52t_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.
70cf8e86
SK
60
61t_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.027425 seconds and 4 git commands to generate.