diff options
author | Björn Gustavsson <[email protected]> | 2016-12-16 12:50:28 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-12-19 11:54:06 +0100 |
commit | a2d92dff3a8acc534daeeb3dea5edda406a6ab0d (patch) | |
tree | a61765af69f9cca94879083422571be3c959bd8c /lib/stdlib/test/dict_SUITE.erl | |
parent | 8362491325db87bd7d561399f8ef8c849df22d33 (diff) | |
download | otp-a2d92dff3a8acc534daeeb3dea5edda406a6ab0d.tar.gz otp-a2d92dff3a8acc534daeeb3dea5edda406a6ab0d.tar.bz2 otp-a2d92dff3a8acc534daeeb3dea5edda406a6ab0d.zip |
Add take/2 to all dictionary modules
Similar to maps:take/2, add take/2 to the other dictionary
modules in STDLIB:
orddict:take(Key, Dict) -> {Val,NewDict} | 'error'.
dict:take(Key, Dict) -> {Val,NewDict} | 'error'.
gb_trees:take(Key, Dict) -> {Val,NewDict}.
For gb_trees also add:
gb_trees:take_any(Key, Dict) -> {Val,NewDict} | 'error'.
gb_trees already has delete() and delete_any(), so we will
follow that design pattern.
Suggested by Boris Bochkaryov in https://github.com/erlang/otp/pull/1209.
Diffstat (limited to 'lib/stdlib/test/dict_SUITE.erl')
-rw-r--r-- | lib/stdlib/test/dict_SUITE.erl | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/stdlib/test/dict_SUITE.erl b/lib/stdlib/test/dict_SUITE.erl index 47358d729f..e99af9ad42 100644 --- a/lib/stdlib/test/dict_SUITE.erl +++ b/lib/stdlib/test/dict_SUITE.erl @@ -23,10 +23,10 @@ -module(dict_SUITE). --export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, +-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, init_per_testcase/2,end_per_testcase/2, - create/1,store/1,iterate/1]). + create/1,store/1,iterate/1,remove/1]). -include_lib("common_test/include/ct.hrl"). @@ -37,7 +37,7 @@ suite() -> {timetrap,{minutes,5}}]. all() -> - [create, store, iterate]. + [create, store, remove, iterate]. groups() -> []. @@ -92,6 +92,27 @@ store_1(List, M) -> end, D0. +remove(_Config) -> + test_all([{0,87}], fun remove_1/2). + +remove_1(List0, M) -> + %% Make sure that keys are unique. Randomize key order. + List1 = orddict:from_list(List0), + List2 = lists:sort([{rand:uniform(),E} || E <- List1]), + List = [E || {_,E} <- List2], + D0 = M(from_list, List), + remove_2(List, D0, M). + +remove_2([{Key,Val}|T], D0, M) -> + {Val,D1} = M(take, {Key,D0}), + error = M(take, {Key,D1}), + D2 = M(erase, {Key,D0}), + true = M(equal, {D1,D2}), + remove_2(T, D1, M); +remove_2([], D, M) -> + true = M(is_empty, D), + D. + %%% %%% Test specifics for gb_trees. %%% |