-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstepper_test.go
36 lines (33 loc) · 899 Bytes
/
stepper_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
package progressbar_test
import (
"strconv"
"testing"
)
func TestFloatFormat(t *testing.T) {
fltfmt := func(f float64) string {
return strconv.FormatFloat(f, 'f', 1, 64) + "%" // don't worry about there is no multiply by 100 at first, here is just a demo
// see the more safe implement of fltfmtpercent() at stepper_fmt.go.
}
for i, cs := range []struct { //nolint:govet //can be reordered
given float64
expect string
}{
{0.71, "0.7%"},
{0.75, "0.8%"},
{1.01, "1.0%"},
{1.0, "1.0%"},
{1.05, "1.1%"},
{1.5, "1.5%"},
} {
got := fltfmt(cs.given)
if got != cs.expect {
t.Fatalf(`%5d. case fltfmt(%v) -> %q, but got %q`, i, cs.given, cs.expect, got)
} else {
t.Logf(`%5d. case fltfmt(%v) -> %q, passed.`, i, cs.given, cs.expect)
}
}
// t.Logf("%v", fltfmt(0.71))
// t.Logf("%v", fltfmt(0.75))
// t.Logf("%v", fltfmt(1.01))
// t.Logf("%v", fltfmt(1.0))
}