aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2015-06-22 17:49:07 +0200
committerSverker Eriksson <[email protected]>2015-06-22 17:49:07 +0200
commit0375ffb60c9ce2d8e65333bbe79aabfa7395aea2 (patch)
tree21738cc8d4ec3952913c69473e748a42cfa8878f /erts/emulator/test
parentf7ef9fb1679fcd46c48ec5f8a968f7e053b3d4ed (diff)
downloadotp-0375ffb60c9ce2d8e65333bbe79aabfa7395aea2.tar.gz
otp-0375ffb60c9ce2d8e65333bbe79aabfa7395aea2.tar.bz2
otp-0375ffb60c9ce2d8e65333bbe79aabfa7395aea2.zip
erts: Expand test map_SUITE:t_bif_merge_and_check
with merge of randomized maps.
Diffstat (limited to 'erts/emulator/test')
-rw-r--r--erts/emulator/test/map_SUITE.erl44
1 files changed, 44 insertions, 0 deletions
diff --git a/erts/emulator/test/map_SUITE.erl b/erts/emulator/test/map_SUITE.erl
index 527b6987fa..4a8240a9b4 100644
--- a/erts/emulator/test/map_SUITE.erl
+++ b/erts/emulator/test/map_SUITE.erl
@@ -2390,6 +2390,9 @@ check_keys_exist([K|Ks],M) ->
check_keys_exist(Ks,M).
t_bif_merge_and_check(Config) when is_list(Config) ->
+
+ io:format("rand:export_seed() -> ~p\n",[rand:export_seed()]),
+
%% simple disjunct ones
%% make sure all keys are unique
Kss = [[a,b,c,d],
@@ -2437,8 +2440,49 @@ t_bif_merge_and_check(Config) when is_list(Config) ->
M41 = maps:merge(M4,M1),
ok = check_key_values(KVs1 ++ [{d,5}] ++ KVs, M41),
+ [begin Ma = random_map(SzA, a),
+ Mb = random_map(SzB, b),
+ ok = merge_maps(Ma, Mb)
+ end || SzA <- [3,10,20,100,200,1000], SzB <- [3,10,20,100,200,1000]],
+
ok.
+% Generate random map with an average of Sz number of pairs: K -> {V,K}
+random_map(Sz, V) ->
+ random_map_insert(#{}, 0, V, Sz*2).
+
+random_map_insert(M0, K0, _, Sz) when K0 > Sz ->
+ M0;
+random_map_insert(M0, K0, V, Sz) ->
+ Key = K0 + rand:uniform(3),
+ random_map_insert(M0#{Key => {V,Key}}, Key, V, Sz).
+
+
+merge_maps(A, B) ->
+ AB = maps:merge(A, B),
+ %%io:format("A=~p\nB=~p\n",[A,B]),
+ maps_foreach(fun(K,VB) -> VB = maps:get(K, AB)
+ end, B),
+ maps_foreach(fun(K,VA) ->
+ case {maps:get(K, AB),maps:find(K, B)} of
+ {VA, error} -> ok;
+ {VB, {ok, VB}} -> ok
+ end
+ end, A),
+
+ maps_foreach(fun(K,V) ->
+ case {maps:find(K, A),maps:find(K, B)} of
+ {{ok, V}, error} -> ok;
+ {error, {ok, V}} -> ok;
+ {{ok,_}, {ok, V}} -> ok
+ end
+ end, AB),
+ ok.
+
+maps_foreach(Fun, Map) ->
+ maps:fold(fun(K,V,_) -> Fun(K,V) end, void, Map).
+
+
check_key_values([],_) -> ok;
check_key_values([{K,V}|KVs],M) ->
V = maps:get(K,M),