From commits-return-33329-archive-asf-public=cust-asf.ponee.io@couchdb.apache.org Sat Jun 16 23:57:06 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 308C7180671 for ; Sat, 16 Jun 2018 23:57:05 +0200 (CEST) Received: (qmail 97881 invoked by uid 500); 16 Jun 2018 21:57:05 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 97802 invoked by uid 99); 16 Jun 2018 21:57:05 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jun 2018 21:57:05 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id AE6928075B; Sat, 16 Jun 2018 21:57:04 +0000 (UTC) Date: Sat, 16 Jun 2018 21:57:06 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb] 02/02: Fix couch_key_tree_tests.erl MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: davisp@apache.org In-Reply-To: <152918622444.17269.3084845252044710203@gitbox.apache.org> References: <152918622444.17269.3084845252044710203@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: 3c9838528972ec55165fdd98bc70cec0bff4db3d X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20180616215704.AE6928075B@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. davisp pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/couchdb.git commit 3c9838528972ec55165fdd98bc70cec0bff4db3d Author: Paul J. Davis AuthorDate: Wed Jun 13 13:35:00 2018 -0500 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 --- src/couch/test/couch_key_tree_tests.erl | 24 +++++++++++++++++++----- 1 file 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 88d9203..2b7d5fe 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", []}}, -- To stop receiving notification emails like this one, please contact davisp@apache.org.