tests/cut_the_tree/test_models.go

40 lines
734 B
Go

package main
import (
"github.com/google/uuid"
"maps"
)
type TestTree struct {
Tree *Node
Weights map[string]uint16
}
func getTestTree(branches, depth int) TestTree {
if depth == 0 {
return TestTree{}
}
id := uuid.NewString()
node := &Node{
ID: id,
Name: id,
}
tree := TestTree{
Tree: node,
Weights: map[string]uint16{id: node.getNodeWeight()},
}
for i := 0; i < branches; i++ {
childTree := getTestTree(branches, depth-1)
if childTree.Tree != nil {
tree.Tree.Children = append(tree.Tree.Children, childTree.Tree)
maps.Copy(tree.Weights, childTree.Weights)
}
}
for _, child := range tree.Tree.Children {
tree.Weights[id] = tree.Weights[id] + tree.Weights[child.ID]
}
return tree
}