-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
89 lines (83 loc) · 1.42 KB
/
utils_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
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
package timex
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAppendInt(t *testing.T) {
tests := []struct {
n int
width int
s string
}{
{-12, 0, "-12"},
{-12, 1, "-12"},
{-12, 2, "-12"},
{-12, 3, "-012"},
{-12, 4, "-0012"},
{-1, 0, "-1"},
{-1, 1, "-1"},
{-1, 2, "-01"},
{-1, 3, "-001"},
{0, 0, "0"},
{0, 1, "0"},
{0, 2, "00"},
{0, 3, "000"},
{1, 0, "1"},
{1, 1, "1"},
{1, 2, "01"},
{1, 3, "001"},
{12, 0, "12"},
{12, 1, "12"},
{12, 2, "12"},
{12, 3, "012"},
{12, 4, "0012"},
{123, 0, "123"},
{123, 1, "123"},
{123, 2, "123"},
{123, 3, "123"},
{123, 4, "0123"},
}
for _, tt := range tests {
bytes := appendInt(nil, tt.n, tt.width)
assert.Equal(t, tt.s, string(bytes))
}
}
func TestAppendFraction(t *testing.T) {
tests := []struct {
n int
width int
s string
}{
{0, 0, ""},
{0, 1, ""},
{0, 2, ""},
{0, 3, ""},
{1, 0, ""},
{1, 1, ".1"},
{1, 2, ".01"},
{1, 3, ".001"},
{10, 0, ""},
{10, 1, ""},
{10, 2, ".1"},
{10, 3, ".01"},
{12, 0, ""},
{12, 1, ".2"},
{12, 2, ".12"},
{12, 3, ".012"},
{12, 4, ".0012"},
{100, 0, ""},
{100, 1, ""},
{100, 2, ""},
{100, 3, ".1"},
{100, 4, ".01"},
{123, 0, ""},
{123, 1, ".3"},
{123, 2, ".23"},
{123, 3, ".123"},
{123, 4, ".0123"},
}
for _, tt := range tests {
bytes := appendFraction(nil, tt.n, tt.width)
assert.Equal(t, tt.s, string(bytes))
}
}