package main import ( "github.com/stretchr/testify/assert" "testing" ) func TestNode_WeighingTreeAllAlgo(t *testing.T) { for name,tt := range map[string]TestTree{ "Ordinary VFS tree": getTestTree(4, 4), "VFS in the form of a pathological tree":getTestTree(1, 100), }{ t.Run(name,func(t *testing.T) { assert.EqualValues(t, tt.Weights, tt.Tree.WeightingTreeWithRecursion()) assert.EqualValues(t, tt.Weights, tt.Tree.WeightingTreeWithStack()) assert.EqualValues(t, tt.Weights, tt.Tree.WeightingTreeWithDLL()) }) } } func TestNode_DecomposeTree(t *testing.T) { } func Benchmark(b *testing.B) { b.StopTimer() b.ResetTimer() for name,tt := range map[string]struct{ branches int depth int }{ "Small tree (85 nodes)":{4, 4}, // 85 nodes, "Wide tree (2,65K nodes)": {515, 3}, // 265'741 nodes, "Deep tree (2,65K nodes)": {3, 12}, // 265'720 nodes, "Huge tree (2,44M nodes)": {5, 10}, // 2'441'406 nodes, "Pathological tree (10K nodes)": {1, 10000}, // 10'000 nodes, }{ b.Run(name, func(b *testing.B) { tree := getTestTree(tt.branches, tt.depth) b.Cleanup(func() { tree = TestTree{nil, nil} }) b.Run("Weighing with recursion", func(b *testing.B) { for i := 0; i < b.N; i++ { b.StartTimer() assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithRecursion()) b.StopTimer() } }) b.Run("Weighting with stack", func(b *testing.B) { for i := 0; i < b.N; i++ { b.StartTimer() assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithStack()) b.StopTimer() } }) b.Run("Weighting with DLL", func(b *testing.B) { for i := 0; i < b.N; i++ { b.StartTimer() assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithDLL()) b.StopTimer() } }) }) } }