From 38996186059e2f0648b02cd60bcfe7345438a840 Mon Sep 17 00:00:00 2001 From: tiburon Date: Mon, 14 Oct 2024 09:23:20 +0300 Subject: [PATCH] Fix all UTs --- weighting_n_cutting_the_tree/cutting_test.go | 13 +- .../cutting_test_models.go | 385 ++++++------------ 2 files changed, 126 insertions(+), 272 deletions(-) diff --git a/weighting_n_cutting_the_tree/cutting_test.go b/weighting_n_cutting_the_tree/cutting_test.go index 8d67bcc..c96db53 100644 --- a/weighting_n_cutting_the_tree/cutting_test.go +++ b/weighting_n_cutting_the_tree/cutting_test.go @@ -1,9 +1,8 @@ package main import ( - "testing" - "github.com/stretchr/testify/require" + "testing" ) func TestDecomposeTree(t *testing.T) { @@ -18,6 +17,11 @@ func TestDecomposeTree(t *testing.T) { outputParts []SubTree err string }{ + "Single node short tree with small threshold": { + inputTree: singleNodeTree.TreeWeighted, + inputThreshold: 10, + err: "[GetNodePath]: threshold too small", + }, "Normal tree 3x3": { inputTree: smallTree.TreeWeighted, inputThreshold: smallTree.Threshold, @@ -28,11 +32,6 @@ func TestDecomposeTree(t *testing.T) { inputThreshold: singleNodeTree.Threshold, outputParts: singleNodeTree.Parts, }, - "Single node short tree with small threshold": { - inputTree: singleNodeTree.TreeWeighted, - inputThreshold: 10, - err: "[GetNodePath]: threshold too small", - }, "Single branch deep tree": { inputTree: deepTree.TreeWeighted, inputThreshold: deepTree.Threshold, diff --git a/weighting_n_cutting_the_tree/cutting_test_models.go b/weighting_n_cutting_the_tree/cutting_test_models.go index 0f5b09c..faa674e 100644 --- a/weighting_n_cutting_the_tree/cutting_test_models.go +++ b/weighting_n_cutting_the_tree/cutting_test_models.go @@ -808,70 +808,53 @@ func getWideTree() testDecomposingData { func getAssimmetricTree() testDecomposingData { newTree := &Node{ - ID: "1.0.0.0", + ID: "0", Name: "/", Children: []*Node{ { - ID: "1.1.0.0", + ID: "01", Name: "folder1", Children: []*Node{ { - ID: "1.1.1.0", - Name: "folder1", + ID: "011", + Name: "folder11", Children: []*Node{ { - ID: "1.1.1.1", - Name: "folder1", + ID: "0111", + Name: "folder111", Children: []*Node{}, }, + }, + }, + { + ID: "012", + Name: "folder12", + Children: []*Node{}, + }, + { + ID: "013", + Name: "folder13", + Children: []*Node{ { - ID: "1.1.1.2", - Name: "folder2", + ID: "0131", + Name: "folder131", Children: []*Node{ { - ID: "1.1.1.1.1", - Name: "folder1.1.1.1.1", + ID: "01311", + Name: "folder1311", 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", + ID: "013111", + Name: "folder13111", Children: []*Node{ { - ID: "1.1.1.1.1.2.1", - Name: "folder1.1.1.1.1.2.1", + ID: "0131111", + Name: "folder131111", 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", + }, + { + ID: "0131112", + Name: "folder131112", Children: []*Node{}, }, }, @@ -881,60 +864,80 @@ func getAssimmetricTree() testDecomposingData { }, }, { - ID: "1.1.1.3", - Name: "folder3", - Children: []*Node{}, - }, - }, - }, - { - ID: "1.1.2.0", - Name: "folder2", - Children: []*Node{ - { - ID: "1.1.2.1", - Name: "folder1", - Children: []*Node{}, + ID: "0132", + Name: "folder132", + Children: []*Node{ + { + ID: "01321", + Name: "folder1321", + Children: []*Node{}, + }, + }, }, { - ID: "1.1.2.2", - Name: "folder2", - Children: []*Node{}, - }, - { - ID: "1.1.2.3", - Name: "folder3", + ID: "0133", + Name: "folder133", Children: []*Node{}, }, }, }, }, }, + { + ID: "02", + Name: "folder2", + Children: []*Node{}, + }, + { + ID: "03", + Name: "folder3", + Children: []*Node{}, + }, + { + ID: "04", + Name: "folder4", + Children: []*Node{}, + }, }, } return testDecomposingData{ TreeWeighted: newTree.WeightingTreeWithStack(), - Threshold: 200, + Threshold: 220, Parts: []SubTree{ { - path: "/folder1", + path: "/folder1/folder13/folder131", tree: &Node{ - ID: "1.1.1.0", - Name: "folder1", + ID: "01311", + Name: "folder1311", Children: []*Node{ { - ID: "1.1.1.1", - Name: "folder1", - Children: []*Node{}, + ID: "013111", + Name: "folder13111", + Children: []*Node{ + { + ID: "0131111", + Name: "folder131111", + Children: []*Node{}, + }, + { + ID: "0131112", + Name: "folder131112", + Children: []*Node{}, + }, + }, }, + }, + }, + }, + { + path: "/folder1/folder13", + tree: &Node{ + ID: "0132", + Name: "folder132", + Children: []*Node{ { - ID: "1.1.1.2", - Name: "folder2", - Children: []*Node{}, - }, - { - ID: "1.1.1.3", - Name: "folder3", + ID: "01321", + Name: "folder1321", Children: []*Node{}, }, }, @@ -943,190 +946,17 @@ func getAssimmetricTree() testDecomposingData { { path: "/folder1", tree: &Node{ - ID: "1.1.2.0", - Name: "folder2", + ID: "013", + Name: "folder13", Children: []*Node{ { - ID: "1.1.2.1", - Name: "folder1", + ID: "0131", + Name: "folder131", Children: []*Node{}, }, { - ID: "1.1.2.2", - Name: "folder2", - Children: []*Node{}, - }, - { - ID: "1.1.2.3", - Name: "folder3", - Children: []*Node{}, - }, - }, - }, - }, - { - path: "/folder1", - tree: &Node{ - 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{}, - }, - }, - }, - }, - { - path: "/folder2", - tree: &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{}, - }, - }, - }, - }, - { - path: "/folder2", - tree: &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{}, - }, - }, - }, - }, - { - path: "/folder2", - tree: &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{}, - }, - }, - }, - }, - { - path: "/folder3", - tree: &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{}, - }, - }, - }, - }, - { - path: "/folder3", - tree: &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{}, - }, - }, - }, - }, - { - path: "/folder3", - tree: &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", + ID: "0133", + Name: "folder133", Children: []*Node{}, }, }, @@ -1135,21 +965,46 @@ func getAssimmetricTree() testDecomposingData { { path: "/", tree: &Node{ - ID: "1.0.0.0", + ID: "01", + Name: "folder1", + Children: []*Node{ + { + ID: "011", + Name: "folder11", + Children: []*Node{ + { + ID: "0111", + Name: "folder111", + Children: []*Node{}, + }, + }, + }, + { + ID: "012", + Name: "folder12", + Children: []*Node{}, + }, + }, + }, + }, + { + path: "/", + tree: &Node{ + ID: "0", Name: "/", Children: []*Node{ { - ID: "1.1.0.0", - Name: "folder1", + ID: "04", + Name: "folder4", Children: []*Node{}, }, { - ID: "1.2.0.0", + ID: "02", Name: "folder2", Children: []*Node{}, }, { - ID: "1.3.0.0", + ID: "03", Name: "folder3", Children: []*Node{}, },