104 lines
2.0 KiB
Go
104 lines
2.0 KiB
Go
package jxutils
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
)
|
|
|
|
func TestSplitSlice(t *testing.T) {
|
|
testValue1 := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
|
list := utils.Interface2Slice(testValue1)
|
|
result := SplitSlice(list, 3)
|
|
if !(len(result) == 4 && len(result[3]) == 1) {
|
|
t.Log("result is not ok")
|
|
}
|
|
|
|
testValue2 := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}
|
|
list = utils.Interface2Slice(testValue2)
|
|
result = SplitSlice(list, 1)
|
|
if !(len(result) == 10 && len(result[3]) == 1) {
|
|
t.Log("result is not ok")
|
|
}
|
|
t.Log(result)
|
|
}
|
|
|
|
func TestGetPolygonFromCircle(t *testing.T) {
|
|
points := GetPolygonFromCircle(104.054727, 30.575362, 1000, 8)
|
|
for _, v := range points {
|
|
t.Log(fmt.Sprintf("lng=%f&lat=%f", v[0], v[1]))
|
|
}
|
|
t.Log(points)
|
|
}
|
|
|
|
func TestFakeID(t *testing.T) {
|
|
id := GenFakeID()
|
|
if !IsFakeID(id) {
|
|
t.Fatalf("wrong result for id:%d", id)
|
|
}
|
|
id = 0
|
|
if !IsFakeID(id) {
|
|
t.Fatalf("wrong result for id:%d", id)
|
|
}
|
|
id = 23424234
|
|
if IsFakeID(id) {
|
|
t.Fatalf("wrong result for id:%d", id)
|
|
}
|
|
}
|
|
|
|
func TestIsMobileFake(t *testing.T) {
|
|
if IsMobileFake("13888888888") {
|
|
t.Fatal("wrong 1")
|
|
}
|
|
if IsMobileFake("13888888888-123") {
|
|
t.Fatal("wrong 2")
|
|
}
|
|
if IsMobileFake("13888888888,123") {
|
|
t.Fatal("wrong 3")
|
|
}
|
|
if !IsMobileFake("138****8888") {
|
|
t.Fatal("wrong 4")
|
|
}
|
|
}
|
|
|
|
func TestSplitStoreName(t *testing.T) {
|
|
for _, v := range [][]string{
|
|
[]string{
|
|
"京西菜市 站北店",
|
|
"京西菜市",
|
|
"站北店",
|
|
},
|
|
[]string{
|
|
"京西菜市(站北店)",
|
|
"京西菜市",
|
|
"站北店",
|
|
},
|
|
[]string{
|
|
"京西菜市[(站北店",
|
|
"京西菜市",
|
|
"站北店",
|
|
},
|
|
[]string{
|
|
"京西菜市 站北店)",
|
|
"京西菜市",
|
|
"站北店",
|
|
},
|
|
[]string{
|
|
"京西菜市-站北店",
|
|
"京西菜市",
|
|
"站北店",
|
|
},
|
|
[]string{
|
|
"站北店",
|
|
"京西菜市",
|
|
"站北店",
|
|
},
|
|
} {
|
|
prefix, bareName := SplitStoreName(v[0], "-", "京西菜市")
|
|
if prefix != v[1] || bareName != v[2] {
|
|
t.Fatalf("SplitStoreName(%s) is wrong, %s, %s", v[0], prefix, bareName)
|
|
}
|
|
}
|
|
}
|