Fix all UTs
continuous-integration/drone/push Build is failing Details

main
Andrey Ivanov 2024-10-14 09:23:20 +03:00
parent 2c038f5a7a
commit 3899618605
2 changed files with 126 additions and 272 deletions

View File

@ -1,9 +1,8 @@
package main package main
import ( import (
"testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing"
) )
func TestDecomposeTree(t *testing.T) { func TestDecomposeTree(t *testing.T) {
@ -18,6 +17,11 @@ func TestDecomposeTree(t *testing.T) {
outputParts []SubTree outputParts []SubTree
err string err string
}{ }{
"Single node short tree with small threshold": {
inputTree: singleNodeTree.TreeWeighted,
inputThreshold: 10,
err: "[GetNodePath]: threshold too small",
},
"Normal tree 3x3": { "Normal tree 3x3": {
inputTree: smallTree.TreeWeighted, inputTree: smallTree.TreeWeighted,
inputThreshold: smallTree.Threshold, inputThreshold: smallTree.Threshold,
@ -28,11 +32,6 @@ func TestDecomposeTree(t *testing.T) {
inputThreshold: singleNodeTree.Threshold, inputThreshold: singleNodeTree.Threshold,
outputParts: singleNodeTree.Parts, outputParts: singleNodeTree.Parts,
}, },
"Single node short tree with small threshold": {
inputTree: singleNodeTree.TreeWeighted,
inputThreshold: 10,
err: "[GetNodePath]: threshold too small",
},
"Single branch deep tree": { "Single branch deep tree": {
inputTree: deepTree.TreeWeighted, inputTree: deepTree.TreeWeighted,
inputThreshold: deepTree.Threshold, inputThreshold: deepTree.Threshold,

View File

@ -808,70 +808,53 @@ func getWideTree() testDecomposingData {
func getAssimmetricTree() testDecomposingData { func getAssimmetricTree() testDecomposingData {
newTree := &Node{ newTree := &Node{
ID: "1.0.0.0", ID: "0",
Name: "/", Name: "/",
Children: []*Node{ Children: []*Node{
{ {
ID: "1.1.0.0", ID: "01",
Name: "folder1", Name: "folder1",
Children: []*Node{ Children: []*Node{
{ {
ID: "1.1.1.0", ID: "011",
Name: "folder1", Name: "folder11",
Children: []*Node{ Children: []*Node{
{ {
ID: "1.1.1.1", ID: "0111",
Name: "folder1", Name: "folder111",
Children: []*Node{}, Children: []*Node{},
}, },
},
},
{
ID: "012",
Name: "folder12",
Children: []*Node{},
},
{
ID: "013",
Name: "folder13",
Children: []*Node{
{ {
ID: "1.1.1.2", ID: "0131",
Name: "folder2", Name: "folder131",
Children: []*Node{ Children: []*Node{
{ {
ID: "1.1.1.1.1", ID: "01311",
Name: "folder1.1.1.1.1", Name: "folder1311",
Children: []*Node{ Children: []*Node{
{ {
ID: "1.1.1.1.1.1", ID: "013111",
Name: "folder1.1.1.1.1.1", Name: "folder13111",
Children: []*Node{},
},
{
ID: "1.1.1.1.1.2",
Name: "folder1.1.1.1.1.2",
Children: []*Node{ Children: []*Node{
{ {
ID: "1.1.1.1.1.2.1", ID: "0131111",
Name: "folder1.1.1.1.1.2.1", Name: "folder131111",
Children: []*Node{}, Children: []*Node{},
}, { },
ID: "1.1.1.1.1.2.2", {
Name: "folder1.1.1.1.1.2.2", ID: "0131112",
Children: []*Node{}, Name: "folder131112",
}, {
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{}, Children: []*Node{},
}, },
}, },
@ -881,60 +864,80 @@ func getAssimmetricTree() testDecomposingData {
}, },
}, },
{ {
ID: "1.1.1.3", ID: "0132",
Name: "folder3", Name: "folder132",
Children: []*Node{}, Children: []*Node{
}, {
}, ID: "01321",
}, Name: "folder1321",
{ Children: []*Node{},
ID: "1.1.2.0", },
Name: "folder2", },
Children: []*Node{
{
ID: "1.1.2.1",
Name: "folder1",
Children: []*Node{},
}, },
{ {
ID: "1.1.2.2", ID: "0133",
Name: "folder2", Name: "folder133",
Children: []*Node{},
},
{
ID: "1.1.2.3",
Name: "folder3",
Children: []*Node{}, Children: []*Node{},
}, },
}, },
}, },
}, },
}, },
{
ID: "02",
Name: "folder2",
Children: []*Node{},
},
{
ID: "03",
Name: "folder3",
Children: []*Node{},
},
{
ID: "04",
Name: "folder4",
Children: []*Node{},
},
}, },
} }
return testDecomposingData{ return testDecomposingData{
TreeWeighted: newTree.WeightingTreeWithStack(), TreeWeighted: newTree.WeightingTreeWithStack(),
Threshold: 200, Threshold: 220,
Parts: []SubTree{ Parts: []SubTree{
{ {
path: "/folder1", path: "/folder1/folder13/folder131",
tree: &Node{ tree: &Node{
ID: "1.1.1.0", ID: "01311",
Name: "folder1", Name: "folder1311",
Children: []*Node{ Children: []*Node{
{ {
ID: "1.1.1.1", ID: "013111",
Name: "folder1", Name: "folder13111",
Children: []*Node{}, 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", ID: "01321",
Name: "folder2", Name: "folder1321",
Children: []*Node{},
},
{
ID: "1.1.1.3",
Name: "folder3",
Children: []*Node{}, Children: []*Node{},
}, },
}, },
@ -943,190 +946,17 @@ func getAssimmetricTree() testDecomposingData {
{ {
path: "/folder1", path: "/folder1",
tree: &Node{ tree: &Node{
ID: "1.1.2.0", ID: "013",
Name: "folder2", Name: "folder13",
Children: []*Node{ Children: []*Node{
{ {
ID: "1.1.2.1", ID: "0131",
Name: "folder1", Name: "folder131",
Children: []*Node{}, Children: []*Node{},
}, },
{ {
ID: "1.1.2.2", ID: "0133",
Name: "folder2", Name: "folder133",
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",
Children: []*Node{}, Children: []*Node{},
}, },
}, },
@ -1135,21 +965,46 @@ func getAssimmetricTree() testDecomposingData {
{ {
path: "/", path: "/",
tree: &Node{ 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: "/", Name: "/",
Children: []*Node{ Children: []*Node{
{ {
ID: "1.1.0.0", ID: "04",
Name: "folder1", Name: "folder4",
Children: []*Node{}, Children: []*Node{},
}, },
{ {
ID: "1.2.0.0", ID: "02",
Name: "folder2", Name: "folder2",
Children: []*Node{}, Children: []*Node{},
}, },
{ {
ID: "1.3.0.0", ID: "03",
Name: "folder3", Name: "folder3",
Children: []*Node{}, Children: []*Node{},
}, },