summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2018-06-13 13:35:00 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2018-06-15 13:49:24 -0500
commit2bbf548d8cd47bfe13efc7dc31719e5daed97a48 (patch)
treec4e1066225704840bcb4b25b2168ca73d21702be
parentf665e9a712175479db3c8040121f50f4b081957c (diff)
downloadcouchdb-optimize-doc-updates.tar.gz
Fix couch_key_tree_tests.erloptimize-doc-updates
The `should_merge_tree_to_itself` and `should_merge_tree_of_odd_length` tests were both invalid as merging does not support merging of anything other than a linear path. This failure was covered up by the fact that the stem operation will detect and cover up any errors from a failed merge. Co-Authored-By: Nick Vatamaniuc <vatamane@apache.org>
-rw-r--r--src/couch/test/couch_key_tree_tests.erl24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/couch/test/couch_key_tree_tests.erl b/src/couch/test/couch_key_tree_tests.erl
index 88d920363..2b7d5fe62 100644
--- a/src/couch/test/couch_key_tree_tests.erl
+++ b/src/couch/test/couch_key_tree_tests.erl
@@ -167,8 +167,23 @@ should_merge_reflexive_for_child_nodes()->
should_merge_tree_to_itself()->
TwoChildSibs = {1, {"1","foo", [{"1a", "bar", []},
{"1b", "bar", []}]}},
- ?_assertEqual({[TwoChildSibs], new_branch},
- couch_key_tree:merge([TwoChildSibs], TwoChildSibs, ?DEPTH)).
+ Leafs = couch_key_tree:get_all_leafs([TwoChildSibs]),
+ Paths = lists:map(fun leaf_to_path/1, Leafs),
+ FinalTree = lists:foldl(fun(Path, TreeAcc) ->
+ {NewTree, internal_node} = couch_key_tree:merge(TreeAcc, Path),
+ NewTree
+ end, [TwoChildSibs], Paths),
+ ?_assertEqual([TwoChildSibs], FinalTree).
+
+leaf_to_path({Value, {Start, Keys}}) ->
+ [Branch] = to_branch(Value, lists:reverse(Keys)),
+ {Start - length(Keys) + 1, Branch}.
+
+to_branch(Value, [Key]) ->
+ [{Key, Value, []}];
+to_branch(Value, [Key | RestKeys]) ->
+ [{Key, [], to_branch(Value, RestKeys)}].
+
should_merge_tree_of_odd_length()->
TwoChild = {1, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}]}},
@@ -176,9 +191,8 @@ should_merge_tree_of_odd_length()->
{"1b", "bar", []}]}},
TwoChildPlusSibs = {1, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]},
{"1b", "bar", []}]}},
-
- ?_assertEqual({[TwoChildPlusSibs], new_branch},
- couch_key_tree:merge([TwoChild], TwoChildSibs, ?DEPTH)).
+ ?_assertEqual({[TwoChildPlusSibs], new_leaf},
+ couch_key_tree:merge([TwoChildSibs], TwoChild, ?DEPTH)).
should_merge_tree_with_stem()->
Stemmed = {2, {"1a", "bar", []}},