diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-26 22:57:10 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-26 22:57:10 +0300 |
| commit | 3d3fcacbdc28c4296b1477e34999011b5a7d93f2 (patch) | |
| tree | 7e383af76f4d38ba971159ac05e9689c0d1ca7bb /internal/flamegraph/trie_test.go | |
| parent | 7f81653beed3f6d0317a23017914a0d9a7d7794a (diff) | |
test: add xo coverage for dual metrics and variable-height flamegraph
Diffstat (limited to 'internal/flamegraph/trie_test.go')
| -rw-r--r-- | internal/flamegraph/trie_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/internal/flamegraph/trie_test.go b/internal/flamegraph/trie_test.go index 47ef770..9f56b15 100644 --- a/internal/flamegraph/trie_test.go +++ b/internal/flamegraph/trie_test.go @@ -167,3 +167,59 @@ func TestInsertTriePathStoresValueAndHeightValueIndependently(t *testing.T) { t.Fatalf("expected leaf heightValue=5, got %d", b.heightValue) } } + +func TestTrieComputeTotalsPropagatesDualMetricsAcrossBranches(t *testing.T) { + tr := newTrie() + insertTriePath(tr.root, []string{"a", "x"}, 5, 100) + insertTriePath(tr.root, []string{"a", "y"}, 3, 40) + insertTriePath(tr.root, []string{"b", "z"}, 7, 1) + tr.computeTotals() + + a := findChild(tr.root, "a") + if a == nil { + t.Fatal("expected node a") + } + b := findChild(tr.root, "b") + if b == nil { + t.Fatal("expected node b") + } + x := findChild(a, "x") + if x == nil { + t.Fatal("expected node x") + } + y := findChild(a, "y") + if y == nil { + t.Fatal("expected node y") + } + + if got, want := x.total, uint64(5); got != want { + t.Fatalf("x total = %d, want %d", got, want) + } + if got, want := x.heightTotal, uint64(100); got != want { + t.Fatalf("x heightTotal = %d, want %d", got, want) + } + if got, want := y.total, uint64(3); got != want { + t.Fatalf("y total = %d, want %d", got, want) + } + if got, want := y.heightTotal, uint64(40); got != want { + t.Fatalf("y heightTotal = %d, want %d", got, want) + } + if got, want := a.total, uint64(8); got != want { + t.Fatalf("a total = %d, want %d", got, want) + } + if got, want := a.heightTotal, uint64(140); got != want { + t.Fatalf("a heightTotal = %d, want %d", got, want) + } + if got, want := b.total, uint64(7); got != want { + t.Fatalf("b total = %d, want %d", got, want) + } + if got, want := b.heightTotal, uint64(1); got != want { + t.Fatalf("b heightTotal = %d, want %d", got, want) + } + if got, want := tr.root.total, uint64(15); got != want { + t.Fatalf("root total = %d, want %d", got, want) + } + if got, want := tr.root.heightTotal, uint64(141); got != want { + t.Fatalf("root heightTotal = %d, want %d", got, want) + } +} |
