-callback get(t(K, V), K) ->
hope_option:t(V).
+-callback get(t(K, V), K, V) ->
+ V.
+
-callback set(t(K, V), K, V) ->
t(K, V).
-export(
[ empty/0
, get/2
+ , get/3
, set/3
, update/3
, pop/2
; {K, V} -> {some, V}
end.
+-spec get(t(K, V), K, V) ->
+ V.
+get(T, K, Default) ->
+ Vopt = get(T, K),
+ hope_option:get(Vopt, Default).
+
-spec set(t(K, V), K, V) ->
t(K, V).
set(T, K, V) ->
-module(hope_dictionary_SUITE).
--include_lib("proper/include/proper.hrl").
-
%% Callbacks
-export(
[ all/0
-export(
[ t_set_new/1
, t_set_existing/1
+ , t_get/1
, t_pop/1
, t_fold/1
, t_dictionary_specs/1
Tests =
[ t_set_new
, t_set_existing
+ , t_get
, t_pop
, t_fold
, t_dictionary_specs
%% Test cases
%% =============================================================================
+t_get(Cfg) ->
+ {some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
+ K1 = k1,
+ K2 = k2,
+ V1 = v1,
+ V2 = v2,
+ D = DictModule:set(DictModule:empty(), K1, V1),
+ {some, V1} = DictModule:get(D, K1),
+ V1 = DictModule:get(D, K1, V2),
+ none = DictModule:get(D, K2),
+ V2 = DictModule:get(D, K2, V2).
+
t_set_new(Cfg) ->
{some, DictModule} = hope_kv_list:get(Cfg, ?DICT_MODULE),
Key = key,