diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2018-06-13 13:35:00 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2018-06-16 16:56:53 -0500 |
commit | 3c9838528972ec55165fdd98bc70cec0bff4db3d (patch) | |
tree | c4e1066225704840bcb4b25b2168ca73d21702be | |
parent | aebdbc452573f70f4e50d88af5814d0fbe936333 (diff) | |
download | couchdb-3c9838528972ec55165fdd98bc70cec0bff4db3d.tar.gz |
Fix couch_key_tree_tests.erl
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.erl | 24 |
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", []}}, |