diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-11-02 16:09:36 -0500 |
---|---|---|
committer | Nick Vatamaniuc <vatamane@apache.org> | 2018-01-15 17:37:46 -0500 |
commit | 05f52abc8a16b04b0a179b23b846c4a7c931638d (patch) | |
tree | 93c9beedd0f2cac726909e60b18f4a171cd8d6a7 | |
parent | 4c490b0792381dfa6c219ccbb246b1a9dcc106be (diff) | |
download | couchdb-05f52abc8a16b04b0a179b23b846c4a7c931638d.tar.gz |
Fix should_merge_tree_to_itself test
This test was invalid as merging does not support anything other than a
linear path. The fact that this was passing before is merely and
oversight that was covered up by stemming completely disassembling and
reassembling the tree after a failed merge.
-rw-r--r-- | src/couch/test/couch_key_tree_tests.erl | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/couch/test/couch_key_tree_tests.erl b/src/couch/test/couch_key_tree_tests.erl index 88d920363..399d5b17c 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", []}]}]}}, |