forked from grafana/k6
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Better number formatting all around
- v0.23.1
- v0.23.0
- v0.22.1
- v0.22.0
- v0.21.1
- v0.21.0
- v0.20.0
- v0.19.0
- v0.18.2
- v0.18.1
- v0.18.0
- v0.17.2
- v0.17.1
- v0.17.0
- v0.16.0
- v0.15.0
- v0.14.0
- v0.13.0
- v0.12.2
- v0.12.1
- v0.11.0
- v0.10.0
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.0
- v0.6.0
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.5
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
uppfinnarn
committed
Dec 2, 2016
1 parent
9a585a7
commit 02044a2
Showing
4 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package stats | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestMetricHumanizeValue(t *testing.T) { | ||
data := map[*Metric]map[float64]string{ | ||
&Metric{Type: Counter, Contains: Default}: map[float64]string{ | ||
1.0: "1", | ||
1.5: "1.5", | ||
1.54321: "1.54321", | ||
}, | ||
&Metric{Type: Gauge, Contains: Default}: map[float64]string{ | ||
1.0: "1", | ||
1.5: "1.5", | ||
1.54321: "1.54321", | ||
}, | ||
&Metric{Type: Trend, Contains: Default}: map[float64]string{ | ||
1.0: "1", | ||
1.5: "1.5", | ||
1.54321: "1.54321", | ||
}, | ||
&Metric{Type: Counter, Contains: Time}: map[float64]string{ | ||
float64(1): "1ns", | ||
float64(12): "12ns", | ||
float64(123): "123ns", | ||
float64(1234): "1.23µs", | ||
float64(12345): "12.34µs", | ||
float64(123456): "123.45µs", | ||
float64(1234567): "1.23ms", | ||
float64(12345678): "12.34ms", | ||
float64(123456789): "123.45ms", | ||
float64(1234567890): "1.23s", | ||
float64(12345678901): "12.34s", | ||
float64(123456789012): "2m3s", | ||
float64(1234567890123): "20m34s", | ||
float64(12345678901234): "3h25m45s", | ||
float64(123456789012345): "34h17m36s", | ||
}, | ||
&Metric{Type: Gauge, Contains: Time}: map[float64]string{ | ||
float64(1): "1ns", | ||
float64(12): "12ns", | ||
float64(123): "123ns", | ||
float64(1234): "1.23µs", | ||
float64(12345): "12.34µs", | ||
float64(123456): "123.45µs", | ||
float64(1234567): "1.23ms", | ||
float64(12345678): "12.34ms", | ||
float64(123456789): "123.45ms", | ||
float64(1234567890): "1.23s", | ||
float64(12345678901): "12.34s", | ||
float64(123456789012): "2m3s", | ||
float64(1234567890123): "20m34s", | ||
float64(12345678901234): "3h25m45s", | ||
float64(123456789012345): "34h17m36s", | ||
}, | ||
&Metric{Type: Trend, Contains: Time}: map[float64]string{ | ||
float64(1): "1ns", | ||
float64(12): "12ns", | ||
float64(123): "123ns", | ||
float64(1234): "1.23µs", | ||
float64(12345): "12.34µs", | ||
float64(123456): "123.45µs", | ||
float64(1234567): "1.23ms", | ||
float64(12345678): "12.34ms", | ||
float64(123456789): "123.45ms", | ||
float64(1234567890): "1.23s", | ||
float64(12345678901): "12.34s", | ||
float64(123456789012): "2m3s", | ||
float64(1234567890123): "20m34s", | ||
float64(12345678901234): "3h25m45s", | ||
float64(123456789012345): "34h17m36s", | ||
}, | ||
&Metric{Type: Rate, Contains: Default}: map[float64]string{ | ||
0.0: "0.00%", | ||
0.01: "1.00%", | ||
0.02: "2.00%", | ||
0.022: "2.20%", | ||
0.0222: "2.22%", | ||
0.02222: "2.22%", | ||
0.022222: "2.22%", | ||
0.5: "50.00%", | ||
0.55: "55.00%", | ||
0.555: "55.50%", | ||
0.5555: "55.55%", | ||
0.55555: "55.55%", | ||
0.75: "75.00%", | ||
1.0: "100.00%", | ||
1.5: "150.00%", | ||
}, | ||
} | ||
|
||
for m, values := range data { | ||
t.Run(fmt.Sprintf("type=%s,contains=%s", m.Type.String(), m.Contains.String()), func(t *testing.T) { | ||
for v, s := range values { | ||
t.Run(fmt.Sprintf("v=%f", v), func(t *testing.T) { | ||
assert.Equal(t, s, m.HumanizeValue(v)) | ||
}) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters