summaryrefslogtreecommitdiff
path: root/internal/tui/flamegraph/testdata_fixture_test.go
blob: 1f22c266bdc8e2d9969044c8d357858228f31e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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")
	}
}