Codebase list golang-github-vbauerster-mpb / f4d85d6
TestPercentageType Vladimir Bauer 3 years ago
1 changed file(s) with 58 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 package decor
1
2 import (
3 "fmt"
4 "testing"
5 )
6
7 func TestPercentageType(t *testing.T) {
8 cases := map[string]struct {
9 value float64
10 verb string
11 expected string
12 }{
13 "10 %d": {10, "%d", "10%"},
14 "10 %s": {10, "%s", "10%"},
15 "10 %f": {10, "%f", "10.000000%"},
16 "10 %.6f": {10, "%.6f", "10.000000%"},
17 "10 %.0f": {10, "%.0f", "10%"},
18 "10 %.1f": {10, "%.1f", "10.0%"},
19 "10 %.2f": {10, "%.2f", "10.00%"},
20 "10 %.3f": {10, "%.3f", "10.000%"},
21
22 "10 % d": {10, "% d", "10 %"},
23 "10 % s": {10, "% s", "10 %"},
24 "10 % f": {10, "% f", "10.000000 %"},
25 "10 % .6f": {10, "% .6f", "10.000000 %"},
26 "10 % .0f": {10, "% .0f", "10 %"},
27 "10 % .1f": {10, "% .1f", "10.0 %"},
28 "10 % .2f": {10, "% .2f", "10.00 %"},
29 "10 % .3f": {10, "% .3f", "10.000 %"},
30
31 "10.5 %d": {10.5, "%d", "10%"},
32 "10.5 %s": {10.5, "%s", "10%"},
33 "10.5 %f": {10.5, "%f", "10.500000%"},
34 "10.5 %.6f": {10.5, "%.6f", "10.500000%"},
35 "10.5 %.0f": {10.5, "%.0f", "10%"},
36 "10.5 %.1f": {10.5, "%.1f", "10.5%"},
37 "10.5 %.2f": {10.5, "%.2f", "10.50%"},
38 "10.5 %.3f": {10.5, "%.3f", "10.500%"},
39
40 "10.5 % d": {10.5, "% d", "10 %"},
41 "10.5 % s": {10.5, "% s", "10 %"},
42 "10.5 % f": {10.5, "% f", "10.500000 %"},
43 "10.5 % .6f": {10.5, "% .6f", "10.500000 %"},
44 "10.5 % .0f": {10.5, "% .0f", "10 %"},
45 "10.5 % .1f": {10.5, "% .1f", "10.5 %"},
46 "10.5 % .2f": {10.5, "% .2f", "10.50 %"},
47 "10.5 % .3f": {10.5, "% .3f", "10.500 %"},
48 }
49 for name, tc := range cases {
50 t.Run(name, func(t *testing.T) {
51 got := fmt.Sprintf(tc.verb, percentageType(tc.value))
52 if got != tc.expected {
53 t.Fatalf("expected: %q, got: %q\n", tc.expected, got)
54 }
55 })
56 }
57 }