aboutsummaryrefslogtreecommitdiff
path: root/gen/map.erl
diff options
context:
space:
mode:
Diffstat (limited to 'gen/map.erl')
-rw-r--r--gen/map.erl62
1 files changed, 54 insertions, 8 deletions
diff --git a/gen/map.erl b/gen/map.erl
index db29fd0..c2a07d4 100644
--- a/gen/map.erl
+++ b/gen/map.erl
@@ -1,10 +1,8 @@
-module(map).
+-compile(no_auto_import).
-include_lib("eunit/include/eunit.hrl").
--export([new/0, size/1, to_list/1, from_list/1, fetch/2, map_values/2, keys/1, values/1, filter/2]).
-
-new() ->
- maps:new().
+-export([size/1, to_list/1, from_list/1, has_key/2, new/0, fetch/2, put/3, map_values/2, keys/1, values/1, filter/2]).
size(A) ->
maps:size(A).
@@ -19,8 +17,38 @@ from_list(A) ->
from_list_test() ->
Proplist = [{4, 0}, {1, 0}],
Map = from_list(Proplist),
- _ = (fun(Capture1) -> expect:equal(Capture1, 2) end)(size(Map)),
- (fun(Capture1) -> expect:equal(Capture1, Proplist) end)(to_list(Map)).
+ (fun(Capture1) -> expect:equal(Capture1, 2) end)(size(Map)).
+-endif.
+
+is_key(A, B) ->
+ maps:is_key(A, B).
+
+has_key(Map, Key) ->
+ is_key(Key, Map).
+
+-ifdef(TEST).
+has_key_test() ->
+ _ = expect:false((fun(Capture1) ->
+ has_key(Capture1, 1)
+ end)(from_list([]))),
+ _ = expect:true((fun(Capture1) ->
+ has_key(Capture1, 1)
+ end)(from_list([{1, 0}]))),
+ _ = expect:true((fun(Capture1) ->
+ has_key(Capture1, 1)
+ end)(from_list([{4, 0}, {1, 0}]))),
+ expect:false((fun(Capture1) ->
+ has_key(Capture1, 0)
+ end)(from_list([{4, 0}, {1, 0}]))).
+-endif.
+
+new() ->
+ maps:new().
+
+-ifdef(TEST).
+new_test() ->
+ _ = (fun(Capture1) -> expect:equal(Capture1, 0) end)(size(new())),
+ (fun(Capture1) -> expect:equal(Capture1, []) end)(to_list(new())).
-endif.
fetch(A, B) ->
@@ -38,6 +66,24 @@ fetch_test() ->
end)((fun(Capture1) -> fetch(Capture1, 1) end)(Map)).
-endif.
+erl_put(A, B, C) ->
+ maps:put(A, B, C).
+
+put(Map, Key, Value) ->
+ erl_put(Key, Value, Map).
+
+-ifdef(TEST).
+put_test() ->
+ (fun(Capture1) ->
+ expect:equal(Capture1,
+ from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]))
+ end)((fun(Capture1) ->
+ put(Capture1, <<"c">>, 2)
+ end)((fun(Capture1) ->
+ put(Capture1, <<"b">>, 1)
+ end)((fun(Capture1) -> put(Capture1, <<"a">>, 0) end)(new())))).
+-endif.
+
erl_map_values(A, B) ->
maps:map(A, B).
@@ -47,7 +93,7 @@ map_values(Map, Fun) ->
-ifdef(TEST).
map_values_test() ->
(fun(Capture1) ->
- expect:equal(Capture1, from_list([{1, 0}, {2, 3}, {3, 5}]))
+ expect:equal(Capture1, from_list([{1, 1}, {2, 3}, {3, 5}]))
end)((fun(Capture1) ->
map_values(Capture1, fun(K, V) -> K + V end)
end)(from_list([{1, 0}, {2, 1}, {3, 2}]))).
@@ -77,4 +123,4 @@ erl_filter(A, B) ->
maps:filter(A, B).
filter(Map, Fun) ->
- filter(Fun, Map).
+ erl_filter(Fun, Map).