xstr_test.go
1.1 KB
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
package xstr
import (
"testing"
)
func TestJoinInts(t *testing.T) {
// test empty slice
is := []int64{}
s := JoinInts(is)
if s != "" {
t.Errorf("input:%v,output:%s,result is incorrect", is, s)
} else {
t.Logf("input:%v,output:%s", is, s)
}
// test len(slice)==1
is = []int64{1}
s = JoinInts(is)
if s != "1" {
t.Errorf("input:%v,output:%s,result is incorrect", is, s)
} else {
t.Logf("input:%v,output:%s", is, s)
}
// test len(slice)>1
is = []int64{1, 2, 3}
s = JoinInts(is)
if s != "1,2,3" {
t.Errorf("input:%v,output:%s,result is incorrect", is, s)
} else {
t.Logf("input:%v,output:%s", is, s)
}
}
func TestSplitInts(t *testing.T) {
// test empty slice
s := ""
is, err := SplitInts(s)
if err != nil || len(is) != 0 {
t.Error(err)
}
// test split int64
s = "1,2,3"
is, err = SplitInts(s)
if err != nil || len(is) != 3 {
t.Error(err)
}
}
func BenchmarkJoinInts(b *testing.B) {
is := make([]int64, 10000, 10000)
for i := int64(0); i < 10000; i++ {
is[i] = i
}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
JoinInts(is)
}
})
}