tests/cutTheTree/main_test.go

250 lines
5.5 KiB
Go

package cut_the_tree_test
import (
"github.com/stretchr/testify/assert"
"testing"
cut_the_tree "tests/cutTheTree"
)
func TestNode_WeighingTreeWithRecursion(t *testing.T) {
for name,tt := range map[string]struct{
input cut_the_tree.Node
output map[string]uint16
}{
"Ordinary VFS tree":{
input:testOrdinaryVFS,
output: map[string]uint16{"node0":1416, "node01":194, "node011":49, "node012":49, "node013":49, "node02":194, "node021":49, "node022":49, "node023":49, "node03":983,"node031":361, "node0311":210, "node03111":53, "node03112":53, "node03113":53, "node0312":51, "node0313":51, "node032":49, "node033":526, "node0331":51, "node0332":375, "node03321":53, "node03322":53, "node03323":218, "node033231":55, "node033232":55, "node033233":55, "node0333":51},
},
"VFS in the form of a pathological tree":{
input: testPathologicalTree,
output: map[string]uint16{"node0":605, "node01":560, "node012":513, "node0123":464, "node01234":413, "node012345":360, "node0123456":305, "node01234567":248, "node012345678":189, "node0123456789":128, "node0123456789A":65},
},
}{
t.Run(name,func(t *testing.T) {
out := tt.input.WeighingTreeWithRecursion()
assert.EqualValues(t, tt.output, out)
})
}
}
func TestNode_DecomposeTree(t *testing.T) {
}
var testOrdinaryVFS = cut_the_tree.Node{
ID: "node0",
Name: "node0",
Children: []*cut_the_tree.Node{
{
ID: "node01",
Name: "node01",
Children: []*cut_the_tree.Node{
{
ID: "node011",
Name: "node011",
Children: nil,
},
{
ID: "node012",
Name: "node012",
Children: nil,
},
{
ID: "node013",
Name: "node013",
Children: nil,
},
},
},
{
ID: "node02",
Name: "node02",
Children: []*cut_the_tree.Node{
{
ID: "node021",
Name: "node021",
Children: nil,
},
{
ID: "node022",
Name: "node022",
Children: nil,
},
{
ID: "node023",
Name: "node023",
Children: nil,
},
},
},
{
ID: "node03",
Name: "node03",
Children: []*cut_the_tree.Node{
{
ID: "node031",
Name: "node031",
Children: []*cut_the_tree.Node{
{
ID: "node0311",
Name: "node0311",
Children: []*cut_the_tree.Node{
{
ID: "node03111",
Name: "node03111",
Children: nil,
},
{
ID: "node03112",
Name: "node03112",
Children: nil,
},
{
ID: "node03113",
Name: "node03113",
Children: nil,
},
},
},
{
ID: "node0312",
Name: "node0312",
Children: nil,
},
{
ID: "node0313",
Name: "node0313",
Children: nil,
},
},
},
{
ID: "node032",
Name: "node032",
Children: nil,
},
{
ID: "node033",
Name: "node033",
Children: []*cut_the_tree.Node{
{
ID: "node0331",
Name: "node0331",
Children: nil,
},
{
ID: "node0332",
Name: "node0332",
Children: []*cut_the_tree.Node{
{
ID: "node03321",
Name: "node03321",
Children: nil,
},
{
ID: "node03322",
Name: "node03322",
Children: nil,
},
{
ID: "node03323",
Name: "node03323",
Children: []*cut_the_tree.Node{
{
ID: "node033231",
Name: "node033231",
Children: nil,
},
{
ID: "node033232",
Name: "node033232",
Children: nil,
},
{
ID: "node033233",
Name: "node033233",
Children: nil,
},
},
},
},
},
{
ID: "node0333",
Name: "node0333",
Children: nil,
},
},
},
},
},
},
}
var testPathologicalTree = cut_the_tree.Node{
ID:"node0",
Name:"node0",
Children:[]*cut_the_tree.Node{
{
ID: "node01",
Name: "node01",
Children:[]*cut_the_tree.Node{
{
ID: "node012",
Name: "node012",
Children:[]*cut_the_tree.Node{
{
ID: "node0123",
Name: "node0123",
Children:[]*cut_the_tree.Node{
{
ID: "node01234",
Name: "node01234",
Children:[]*cut_the_tree.Node{
{
ID: "node012345",
Name: "node012345",
Children:[]*cut_the_tree.Node{
{
ID: "node0123456",
Name: "node0123456",
Children:[]*cut_the_tree.Node{
{
ID: "node01234567",
Name: "node01234567",
Children:[]*cut_the_tree.Node{
{
ID: "node012345678",
Name: "node012345678",
Children:[]*cut_the_tree.Node{
{
ID: "node0123456789",
Name: "node0123456789",
Children:[]*cut_the_tree.Node{
{
ID: "node0123456789A",
Name: "node0123456789A",
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
}