diff --git a/weighting_n_cutting_the_tree/cutting_test.go b/weighting_n_cutting_the_tree/cutting_test.go index 7e5b6b6..8d67bcc 100644 --- a/weighting_n_cutting_the_tree/cutting_test.go +++ b/weighting_n_cutting_the_tree/cutting_test.go @@ -10,6 +10,7 @@ func TestDecomposeTree(t *testing.T) { smallTree := getSmallTree() singleNodeTree := getSingleNodeTree() deepTree := getDeepTree() + wideTree := getWideTree() assimmetricTree := getAssimmetricTree() for name, tt := range map[string]struct { inputTree map[string]*WeightedNode @@ -37,6 +38,11 @@ func TestDecomposeTree(t *testing.T) { inputThreshold: deepTree.Threshold, outputParts: deepTree.Parts, }, + "Wide tree": { + inputTree: wideTree.TreeWeighted, + inputThreshold: wideTree.Threshold, + outputParts: wideTree.Parts, + }, "Asymmetric tree": { inputTree: assimmetricTree.TreeWeighted, inputThreshold: assimmetricTree.Threshold, diff --git a/weighting_n_cutting_the_tree/cutting_test_models.go b/weighting_n_cutting_the_tree/cutting_test_models.go index 906e546..0f5b09c 100644 --- a/weighting_n_cutting_the_tree/cutting_test_models.go +++ b/weighting_n_cutting_the_tree/cutting_test_models.go @@ -561,7 +561,7 @@ func getDeepTree() testDecomposingData { Threshold: 200, Parts: []SubTree{ { - path: "/folder1/folder2/folder3/folder4/folder5/folder6/folder7/folder8", + path: "/folder2/folder3/folder4/folder5/folder6/folder7/folder8", tree: &Node{ ID: "1.2.3.4.5.6.7.8.9", Name: "folder9", @@ -581,7 +581,7 @@ func getDeepTree() testDecomposingData { }, }, { - path: "/folder1/folder2/folder3/folder4/folder5", + path: "/folder2/folder3/folder4/folder5", tree: &Node{ ID: "1.2.3.4.5.6", Name: "folder6", @@ -638,6 +638,174 @@ func getDeepTree() testDecomposingData { } } +func getWideTree() testDecomposingData { + newTree := &Node{ + ID: "0", + Name: "/", + Children: []*Node{ + { + ID: "0.1", + Name: "folder01", + Children: []*Node{ + { + ID: "0.1.1", + Name: "folder011", + Children: []*Node{ + { + ID: "0.1.1.1", + Name: "folder0111", + Children: []*Node{}, + }, + { + ID: "0.1.1.2", + Name: "folder0112", + Children: []*Node{}, + }, + { + ID: "0.1.1.3", + Name: "folder0113", + Children: []*Node{}, + }, + { + ID: "0.1.1.4", + Name: "folder0114", + Children: []*Node{}, + }, + { + ID: "0.1.1.5", + Name: "folder0115", + Children: []*Node{}, + }, + { + ID: "0.1.1.6", + Name: "folder0116", + Children: []*Node{}, + }, + { + ID: "0.1.1.7", + Name: "folder0117", + Children: []*Node{}, + }, + { + ID: "0.1.1.8", + Name: "folder0118", + Children: []*Node{}, + }, + { + ID: "0.1.1.9", + Name: "folder0119", + Children: []*Node{}, + }, + }, + }, + }, + }, + }, + } + return testDecomposingData{ + TreeWeighted: newTree.WeightingTreeWithStack(), + Threshold: 60, + Parts: []SubTree{ + { + path: "/folder01/folder011", + tree: &Node{ + ID: "0.1.1.1", + Name: "folder0111", + Children: []*Node{}, + }, + }, + { + path: "/folder01/folder011", + tree: &Node{ + ID: "0.1.1.2", + Name: "folder0112", + Children: []*Node{}, + }, + }, + { + path: "/folder01/folder011", + tree: &Node{ + ID: "0.1.1.3", + Name: "folder0113", + Children: []*Node{}, + }, + }, + { + path: "/folder01/folder011", + tree: &Node{ + ID: "0.1.1.4", + Name: "folder0114", + Children: []*Node{}, + }, + }, + { + path: "/folder01/folder011", + tree: &Node{ + ID: "0.1.1.5", + Name: "folder0115", + Children: []*Node{}, + }, + }, + { + path: "/folder01/folder011", + tree: &Node{ + ID: "0.1.1.6", + Name: "folder0116", + Children: []*Node{}, + }, + }, + { + path: "/folder01/folder011", + tree: &Node{ + ID: "0.1.1.7", + Name: "folder0117", + Children: []*Node{}, + }, + }, + { + path: "/folder01/folder011", + tree: &Node{ + ID: "0.1.1.8", + Name: "folder0118", + Children: []*Node{}, + }, + }, + { + path: "/folder01/folder011", + tree: &Node{ + ID: "0.1.1.9", + Name: "folder0119", + Children: []*Node{}, + }, + }, + { + path: "/folder01", + tree: &Node{ + ID: "0.1.1", + Name: "folder011", + Children: []*Node{}, + }, + }, + { + path: "/", + tree: &Node{ + ID: "0.1", + Name: "folder01", + Children: []*Node{}, + }, + }, + { + path: "/", + tree: &Node{ + ID: "0", + Name: "/", + Children: []*Node{}, + }, + }, + }, + } +} + func getAssimmetricTree() testDecomposingData { newTree := &Node{ ID: "1.0.0.0", @@ -657,9 +825,60 @@ func getAssimmetricTree() testDecomposingData { Children: []*Node{}, }, { - ID: "1.1.1.2", - Name: "folder2", - Children: []*Node{}, + ID: "1.1.1.2", + Name: "folder2", + Children: []*Node{ + { + ID: "1.1.1.1.1", + Name: "folder1.1.1.1.1", + Children: []*Node{ + { + ID: "1.1.1.1.1.1", + Name: "folder1.1.1.1.1.1", + Children: []*Node{}, + }, + { + ID: "1.1.1.1.1.2", + Name: "folder1.1.1.1.1.2", + Children: []*Node{ + { + ID: "1.1.1.1.1.2.1", + Name: "folder1.1.1.1.1.2.1", + Children: []*Node{}, + }, { + ID: "1.1.1.1.1.2.2", + Name: "folder1.1.1.1.1.2.2", + Children: []*Node{}, + }, { + ID: "1.1.1.1.1.2.3", + Name: "folder1.1.1.1.1.2.3", + Children: []*Node{}, + }, { + ID: "1.1.1.1.1.2.4", + Name: "folder1.1.1.1.1.2.4", + Children: []*Node{{ + ID: "1.1.1.1.1.2.4.1", + Name: "folder1.1.1.1.1.2.4.1", + Children: []*Node{{ + ID: "1.1.1.1.1.2.4.1.1", + Name: "folder1.1.1.1.1.2.4.1.1", + Children: []*Node{}, + }, { + ID: "1.1.1.1.1.2.4.1.2", + Name: "folder1.1.1.1.1.2.4.1.2", + Children: []*Node{}, + }}, + }}, + }, { + ID: "1.1.1.1.1.2.5", + Name: "folder1.1.1.1.1.2.5", + Children: []*Node{}, + }, + }, + }, + }, + }, + }, }, { ID: "1.1.1.3", @@ -689,165 +908,6 @@ func getAssimmetricTree() testDecomposingData { }, }, }, - { - ID: "1.1.3.0", - Name: "folder3", - Children: []*Node{ - { - ID: "1.1.3.1", - Name: "folder1", - Children: []*Node{}, - }, - { - ID: "1.1.3.2", - Name: "folder2", - Children: []*Node{}, - }, - { - ID: "1.1.3.3", - Name: "folder3", - Children: []*Node{}, - }, - }, - }, - }, - }, - { - ID: "1.2.0.0", - Name: "folder2", - Children: []*Node{ - { - ID: "1.2.1.0", - Name: "folder1", - Children: []*Node{ - { - ID: "1.2.1.1", - Name: "folder1", - Children: []*Node{}, - }, - { - ID: "1.2.1.2", - Name: "folder2", - Children: []*Node{}, - }, - { - ID: "1.2.1.3", - Name: "folder3", - Children: []*Node{}, - }, - }, - }, - { - ID: "1.2.2.0", - Name: "folder2", - Children: []*Node{ - { - ID: "1.2.2.1", - Name: "folder1", - Children: []*Node{}, - }, - { - ID: "1.2.2.2", - Name: "folder2", - Children: []*Node{}, - }, - { - ID: "1.2.2.3", - Name: "folder3", - Children: []*Node{}, - }, - }, - }, - { - ID: "1.2.3.0", - Name: "folder3", - Children: []*Node{ - { - ID: "1.2.3.1", - Name: "folder1", - Children: []*Node{}, - }, - { - ID: "1.2.3.2", - Name: "folder2", - Children: []*Node{}, - }, - { - ID: "1.2.3.3", - Name: "folder3", - Children: []*Node{}, - }, - }, - }, - }, - }, - { - ID: "1.3.0.0", - Name: "folder3", - Children: []*Node{ - { - ID: "1.3.1.0", - Name: "folder1", - Children: []*Node{ - { - ID: "1.3.1.1", - Name: "folder1", - Children: []*Node{}, - }, - { - ID: "1.3.1.2", - Name: "folder2", - Children: []*Node{}, - }, - { - ID: "1.3.1.3", - Name: "folder3", - Children: []*Node{}, - }, - }, - }, - { - ID: "1.3.2.0", - Name: "folder2", - Children: []*Node{ - { - ID: "1.3.2.1", - Name: "folder1", - Children: []*Node{}, - }, - { - ID: "1.3.2.2", - Name: "folder2", - Children: []*Node{}, - }, - { - ID: "1.3.2.3", - Name: "folder3", - Children: []*Node{}, - }, - }, - }, - { - ID: "1.3.3.0", - Name: "folder3", - Children: []*Node{ - { - ID: "1.3.3.1", - Name: "folder1", - Children: []*Node{}, - }, - { - ID: "1.3.3.2", - Name: "folder2", - Children: []*Node{}, - }, - { - ID: "1.3.3.3", - Name: "folder3", - Children: []*Node{}, - }, - }, - }, }, }, },