-
Notifications
You must be signed in to change notification settings - Fork 6
/
itoa_test.go
73 lines (66 loc) · 1.59 KB
/
itoa_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
package gox_test
import (
"strconv"
"testing"
"github.com/goexl/gox"
)
func TestFormatInt(t *testing.T) {
tests := []struct {
in int64
base uint8
expected string
}{
{in: 1, base: 76, expected: "1"},
{in: 2, base: 76, expected: "2"},
{in: 3, base: 76, expected: "3"},
{in: 4, base: 76, expected: "4"},
{in: 5, base: 76, expected: "5"},
{in: 6, base: 76, expected: "6"},
}
for _, test := range tests {
got := gox.FormatInt(test.in, test.base, strconv.FormatInt)
if got != test.expected {
t.Fatalf("期望:%v,实际:%v", test.expected, got)
}
}
}
func TestFormatUint(t *testing.T) {
tests := []struct {
in uint64
base uint8
expected string
}{
{in: 1, base: 76, expected: "1"},
{in: 2, base: 76, expected: "2"},
{in: 3, base: 76, expected: "3"},
{in: 4, base: 76, expected: "4"},
{in: 5, base: 76, expected: "5"},
{in: 6, base: 76, expected: "6"},
}
for _, test := range tests {
got := gox.FormatUint(test.in, test.base, strconv.FormatUint)
if got != test.expected {
t.Fatalf("期望:%v,实际:%v", test.expected, got)
}
}
}
func TestAtoi(t *testing.T) {
tests := []struct {
in string
base int
expected int64
}{
{in: "1", base: 76, expected: 1},
{in: "2", base: 76, expected: 2},
{in: "3", base: 76, expected: 3},
{in: "4", base: 76, expected: 4},
{in: "5", base: 76, expected: 5},
{in: "6", base: 76, expected: 6},
}
for _, test := range tests {
got := gox.Atoi[int64](test.in, test.base)
if got != test.expected {
t.Fatalf("期望:%v,实际:%v", test.expected, got)
}
}
}