diff options
Diffstat (limited to 'gen/test/map_dict_test.erl')
-rw-r--r-- | gen/test/map_dict_test.erl | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/gen/test/map_dict_test.erl b/gen/test/map_dict_test.erl new file mode 100644 index 0000000..e4560d9 --- /dev/null +++ b/gen/test/map_dict_test.erl @@ -0,0 +1,55 @@ +-module(map_dict_test). +-compile(no_auto_import). + +-export([from_list_test/0, has_key_test/0, new_test/0, fetch_test/0, put_test/0, map_values_test/0, keys_test/0, values_test/0]). + +from_list_test() -> + expect:equal(map_dict:size(map_dict:from_list([{4, 0}, {1, 0}])), 2). + +has_key_test() -> + expect:false(map_dict:has_key(map_dict:from_list([]), 1)), + expect:true(map_dict:has_key(map_dict:from_list([{1, 0}]), 1)), + expect:true(map_dict:has_key(map_dict:from_list([{4, 0}, {1, 0}]), 1)), + expect:false(map_dict:has_key(map_dict:from_list([{4, 0}, {1, 0}]), 0)). + +new_test() -> + expect:equal(map_dict:size(map_dict:new()), 0), + expect:equal(map_dict:to_list(map_dict:new()), []). + +fetch_test() -> + Proplist = [{4, 0}, {1, 1}], + M = map_dict:from_list(Proplist), + expect:equal(map_dict:fetch(M, 4), {ok, 0}), + expect:equal(map_dict:fetch(M, 1), {ok, 1}), + expect:is_error(map_dict:fetch(M, 2)). + +put_test() -> + expect:equal(map_dict:put(map_dict:put(map_dict:put(map_dict:new(), + <<"a">>, + 0), + <<"b">>, + 1), + <<"c">>, + 2), + map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}])). + +map_values_test() -> + expect:equal(map_dict:map_values(map_dict:from_list([{1, 0}, + {2, 1}, + {3, 2}]), + fun(K, V) -> K + V end), + map_dict:from_list([{1, 1}, {2, 3}, {3, 5}])). + +keys_test() -> + expect:equal(map_dict:keys(map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}])), + [<<"a">>, <<"b">>, <<"c">>]). + +values_test() -> + expect:equal(map_dict:values(map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}])), + [0, 1, 2]). |