167 lines
3.6 KiB
Go
167 lines
3.6 KiB
Go
package jxutils
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
|
)
|
|
|
|
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 TestIsStringLikeMobile(t *testing.T) {
|
|
if !IsStringLikeMobile("13888888888") {
|
|
t.Fatal("wrong 1")
|
|
}
|
|
if IsStringLikeMobile("13888888888-123") {
|
|
t.Fatal("wrong 2")
|
|
}
|
|
if IsStringLikeMobile("13888888888,123") {
|
|
t.Fatal("wrong 3")
|
|
}
|
|
if IsStringLikeMobile("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)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCalcPolygonAreaAutonavi(t *testing.T) {
|
|
// pointers := GetPolygonFromCircle(104.065702, 30.657488, 3000, 128)
|
|
// area := CalcPolygonAreaAutonavi(pointers)
|
|
// t.Logf("area:%f", area)
|
|
db := dao.GetDB()
|
|
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
strBuilder := &strings.Builder{}
|
|
strBuilder.WriteString("\n")
|
|
for _, v := range storeList {
|
|
if v.DeliveryRangeType == model.DeliveryRangeTypePolygon {
|
|
pointers := CoordinateStr2Points(v.DeliveryRange)
|
|
area1 := CalcPolygonAreaAutonavi(pointers)
|
|
strBuilder.WriteString(fmt.Sprintf("%d,%f\n", v.ID, area1))
|
|
}
|
|
}
|
|
t.Log(strBuilder.String())
|
|
}
|
|
|
|
func TestCaculateSkuPrice(t *testing.T) {
|
|
type tTestInfo struct {
|
|
DesiredPrice int
|
|
UnitPrice int
|
|
SpecQuality float32
|
|
SpecUnit string
|
|
Unit string
|
|
}
|
|
for _, v := range []*tTestInfo{
|
|
&tTestInfo{
|
|
DesiredPrice: 458,
|
|
UnitPrice: 915,
|
|
SpecQuality: 250,
|
|
SpecUnit: "g",
|
|
Unit: "份",
|
|
},
|
|
&tTestInfo{
|
|
DesiredPrice: 123,
|
|
UnitPrice: 123,
|
|
SpecQuality: 888,
|
|
SpecUnit: "g",
|
|
Unit: "个",
|
|
},
|
|
&tTestInfo{
|
|
DesiredPrice: 1,
|
|
UnitPrice: 5,
|
|
SpecQuality: 1,
|
|
SpecUnit: "g",
|
|
Unit: "份",
|
|
},
|
|
} {
|
|
price := CaculateSkuPrice(v.UnitPrice, v.SpecQuality, v.SpecUnit, v.Unit)
|
|
if price != v.DesiredPrice {
|
|
t.Errorf("price:%d,desiredPrice:%d", price, v.DesiredPrice)
|
|
}
|
|
}
|
|
}
|