diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-09-16 14:23:51 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-09-17 13:53:51 -0500 |
commit | 39aa7423b2e79d9859f8626b1678636dba738c9f (patch) | |
tree | 62245e386e75c086b17aea8e11003e37bb3a6578 | |
parent | ffb85f17714330e0ef859e7f79c9c5d230e331f4 (diff) | |
download | couchdb-39aa7423b2e79d9859f8626b1678636dba738c9f.tar.gz |
Fix bug in ebtree:umerge_members/4
Caught during Elixir tests. I've added a unit test to `ebtree.erl` to
ensure we don't regress in the future.
-rw-r--r-- | src/ebtree/src/ebtree.erl | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/ebtree/src/ebtree.erl b/src/ebtree/src/ebtree.erl index 3cfb82030..97a820304 100644 --- a/src/ebtree/src/ebtree.erl +++ b/src/ebtree/src/ebtree.erl @@ -1187,7 +1187,7 @@ umerge_members_int(_Collate, List1, [], Acc) -> umerge_members_int(Collate, [H1 | T1], [H2 | T2], Acc) -> case Collate(H1, H2) of lt -> umerge_members_int(Collate, T1, [H2 | T2], [H1 | Acc]); - eq -> umerge_members_int(Collate, T1, [H2 | T2], [H1 | Acc]); + eq -> umerge_members_int(Collate, T1, T2, [H1 | Acc]); gt -> umerge_members_int(Collate, [H1 | T1], T2, [H2 | Acc]) end. @@ -1800,4 +1800,20 @@ cache_test_() -> ?assertEqual(3, length(NodeCache)) end]}. + +umerge_members_test() -> + Tree = #tree{collate_fun = fun collate_raw/2}, + NewList = fun() -> + Raw = [{rand:uniform(100), rand:uniform()} || _ <- lists:seq(1, 100)], + lists:ukeysort(1, Raw) + end, + lists:foreach(fun(_) -> + A = NewList(), + B = NewList(), + Stdlib = lists:ukeymerge(1, A, B), + Custom = umerge_members(Tree, 0, A, B), + ?assertEqual(Stdlib, Custom) + end, lists:seq(1, 100)). + + -endif. |