-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathtelemetry_renderers_test.go
More file actions
92 lines (89 loc) · 2.11 KB
/
telemetry_renderers_test.go
File metadata and controls
92 lines (89 loc) · 2.11 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (C) 2021-2025 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
package telemetry
import (
"fmt"
"testing"
)
func TestComputeAxisMax(t *testing.T) {
tests := []struct {
name string
data [][]float64
wantEmpty bool // true means expect "" (no constraint)
wantAbove float64
wantBelow float64
}{
{
name: "normal data, no outliers",
data: [][]float64{{10, 12, 11, 13, 10, 12, 11, 14, 10, 13}},
wantEmpty: true,
},
{
name: "single extreme outlier",
data: [][]float64{{10, 12, 11, 13, 10, 12, 11, 14, 10, 10000}},
wantEmpty: false,
wantAbove: 13,
wantBelow: 10000,
},
{
name: "all identical values",
data: [][]float64{{5, 5, 5, 5, 5, 5, 5, 5, 5, 5}},
wantEmpty: true,
},
{
name: "too few data points",
data: [][]float64{{10, 20, 30}},
wantEmpty: true,
},
{
name: "empty data",
data: [][]float64{},
wantEmpty: true,
},
{
name: "multiple datasets, one with outlier",
data: [][]float64{{10, 12, 11, 13, 10}, {11, 14, 10, 13, 50000}},
wantEmpty: false,
wantAbove: 13,
wantBelow: 50000,
},
{
name: "gradual increase, no outlier",
data: [][]float64{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
wantEmpty: true,
},
{
name: "all zeros",
data: [][]float64{{0, 0, 0, 0, 0}},
wantEmpty: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := computeAxisMax(tt.data)
if tt.wantEmpty {
if got != "" {
t.Errorf("computeAxisMax() = %q, want empty string", got)
}
return
}
if got == "" {
t.Errorf("computeAxisMax() = empty string, want a constraining value")
return
}
// Parse and check bounds
var val float64
n, err := fmt.Sscanf(got, "%f", &val)
if err != nil || n != 1 {
t.Errorf("computeAxisMax() = %q, could not parse as float", got)
return
}
if val <= tt.wantAbove {
t.Errorf("computeAxisMax() = %f, want > %f", val, tt.wantAbove)
}
if val >= tt.wantBelow {
t.Errorf("computeAxisMax() = %f, want < %f", val, tt.wantBelow)
}
})
}
}