package main import ( "testing" "github.com/stretchr/testify/require" ) func TestDecomposeTree(t *testing.T){ testTree := getSmallTree() for name, tt := range map[string]struct{ inputTree map[string]*WeightedNode inputThreshold uint16 outputParts []SubTree err string }{ "Normal":{ inputTree: testTree.TreeWeighted, inputThreshold: testTree.Threshold, outputParts: testTree.Parts, }, }{ t.Run(name, func(t *testing.T) { result, err := DecomposeTree(tt.inputTree, tt.inputThreshold) if tt.err == "" { require.NoError(t, err) require.ElementsMatch(t, result, tt.outputParts) } else { require.EqualError(t, err, tt.err) } }) } } func TestGetNodePath(t *testing.T) { testTree := getSmallTree() for name, tt := range map[string]struct{ inputTree map[string]*WeightedNode inputCurrentNodeID string outputPath string outputErr string }{ "Normal path":{ inputTree: testTree.TreeWeighted, inputCurrentNodeID: "1.2.3.3", outputPath: "/folder2/folder3", }, "Short path":{ inputTree: testTree.TreeWeighted, inputCurrentNodeID: "1.0.0.0", outputPath: "/", }, "Not existent node":{ inputTree: testTree.TreeWeighted, inputCurrentNodeID: "qwwrwteyu", outputErr: "node not exists", }, }{ t.Run(name, func(t *testing.T) { path, err := GetNodePath(tt.inputTree, tt.inputCurrentNodeID) require.Equal(t, tt.outputPath, path) if tt.outputErr != "" { require.EqualError(t, err, tt.outputErr) } }) } }