-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathseries_label_test.go
63 lines (47 loc) · 1.51 KB
/
series_label_test.go
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
package charts
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLabelFormatPie(t *testing.T) {
t.Parallel()
assert.Equal(t, "a: 12%",
labelFormatPie([]string{"a", "b"}, "", nil, 0, 10, 0.12))
assert.Equal(t, "b: 25%",
labelFormatPie([]string{"a", "b"}, "", nil, 1, 20, 0.25))
assert.Equal(t, "a: f",
labelFormatPie([]string{"a", "b"}, "{b}: {c}", func(f float64) string {
return "f"
}, 0, 10, 0.12))
}
func TestLabelFormatFunnel(t *testing.T) {
t.Parallel()
assert.Equal(t, "a(12%)",
labelFormatFunnel([]string{"a", "b"}, "", nil, 0, 10, 0.12))
assert.Equal(t, "b(25%)",
labelFormatFunnel([]string{"a", "b"}, "", nil, 1, 20, 0.25))
assert.Equal(t, "b(f, 25%)",
labelFormatFunnel([]string{"a", "b"}, "{b}({c}, {d})", func(f float64) string {
return "f"
}, 1, 20, 0.25))
}
func TestLabelFormatter(t *testing.T) {
t.Parallel()
assert.Equal(t, "10",
labelFormatValue([]string{"a", "b"}, "", nil, 0, 10, 0.12))
assert.Equal(t, "f f 12%",
labelFormatValue([]string{"a", "b"}, "{c} {c} {d}",
func(f float64) string {
return "f"
},
0, 10, 0.12))
assert.Equal(t, "Name: a, Value: 10, Percent: 12%",
labelFormatPie([]string{"a", "b"}, "Name: {b}, Value: {c}, Percent: {d}", nil,
0, 10, 0.12))
assert.Equal(t, "Name: b, Value: 20, Percent: 25%",
labelFormatPie([]string{"a", "b"}, "Name: {b}, Value: {c}, Percent: {d}", nil,
1, 20, 0.25))
assert.Equal(t, "Empty Series '' 20",
labelFormatPie([]string{}, "Empty Series '{b}' {c}", nil,
1, 20, 0.25))
}