From 4953fd0200eef52f7e1547d5961a2e70e24e49d1 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 5 Mar 2026 23:09:31 +0200 Subject: task 367: add flamegraph benchmark fixture generators --- internal/tui/flamegraph/testdata_fixture_test.go | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 internal/tui/flamegraph/testdata_fixture_test.go (limited to 'internal/tui/flamegraph/testdata_fixture_test.go') diff --git a/internal/tui/flamegraph/testdata_fixture_test.go b/internal/tui/flamegraph/testdata_fixture_test.go new file mode 100644 index 0000000..1f22c26 --- /dev/null +++ b/internal/tui/flamegraph/testdata_fixture_test.go @@ -0,0 +1,39 @@ +package flamegraph + +import "testing" + +func TestFixtureSnapshotsHaveApproximateFrameCounts(t *testing.T) { + fixtures := []struct { + name string + depth int + breadth int + expect int + }{ + {name: "small", depth: fixtureSmallDepth, breadth: fixtureSmallBreadth, expect: 121}, + {name: "medium", depth: fixtureMediumDepth, breadth: fixtureMediumBreadth, expect: 2500}, + {name: "large", depth: fixtureLargeDepth, breadth: fixtureLargeBreadth, expect: 12000}, + {name: "deep", depth: fixtureDeepDepth, breadth: fixtureDeepBreadth, expect: 100}, + {name: "wide", depth: fixtureWideDepth, breadth: fixtureWideBreadth, expect: 5000}, + } + + for _, fixture := range fixtures { + t.Run(fixture.name, func(t *testing.T) { + snap := generateTestSnapshot(fixture.depth, fixture.breadth) + got := snapshotNodeCount(snap) + if !approxEqualCount(got, fixture.expect) { + t.Fatalf("%s fixture nodes=%d, expected approximately %d", fixture.name, got, fixture.expect) + } + }) + } +} + +func TestGenerateTestTrieProducesSnapshotData(t *testing.T) { + lt := generateTestTrie(fixtureSmallDepth, fixtureSmallBreadth) + snap, err := decodeTrieSnapshot(lt) + if err != nil { + t.Fatalf("decode trie snapshot: %v", err) + } + if snap.Total == 0 { + t.Fatalf("expected generated trie snapshot to contain data") + } +} -- cgit v1.2.3