Files
jx-callback/business/jxutils/jxutils_test.go
2018-08-30 00:32:57 +08:00

69 lines
2.8 KiB
Go

package jxutils
import (
"fmt"
"testing"
)
func TestEarthDistance(t *testing.T) {
lat1, lng1 := 32.060255, 118.796877
lat2, lng2 := 39.904211, 116.407395
distance := EarthDistance(lat1, lng1, lat2, lng2)
fmt.Print(distance)
}
func TestMapValue2Scope(t *testing.T) {
result := MapValue2Scope(-4, -10, 0, 0, 100)
if result != 60 {
t.Fatalf("result:%d is wrong", result)
}
result = MapValue2Scope(-4, 0, 10, 0, 100)
if result != 0 {
t.Fatalf("result:%d is wrong", result)
}
result = MapValue2Scope(100, 0, 10, 0, 100)
if result != 100 {
t.Fatalf("result:%d is wrong", result)
}
}
func TestGetNameAndUnitFromSkuName(t *testing.T) {
name, unit := GetNameAndUnitFromSkuName("【满59免运】蒜苔肉丝约400g/个(蒜苔约250g 肉丝约150g/份)")
if name != "【满59免运】蒜苔肉丝约400g" || unit != "个" {
t.Fatalf("TestGetNameAndUnitFromSkuName wrong, name:%s, unit:%s", name, unit)
}
name, unit = GetNameAndUnitFromSkuName("【满59免运】蒜苔肉丝约400g/g份(蒜苔约250g 肉丝约150g/份)")
if name != "【满59免运】蒜苔肉丝约400g" || unit != "g" {
t.Fatalf("TestGetNameAndUnitFromSkuName wrong, name:%s, unit:%s", name, unit)
}
name, unit = GetNameAndUnitFromSkuName("【满59免运】蒜苔肉丝约400g/个")
if name != "【满59免运】蒜苔肉丝约400g" || unit != "个" {
t.Fatalf("TestGetNameAndUnitFromSkuName wrong, name:%s, unit:%s", name, unit)
}
name, unit = GetNameAndUnitFromSkuName("【满59免运】蒜苔肉丝约400g/")
if name != "【满59免运】蒜苔肉丝约400g" || unit != "份" {
t.Fatalf("TestGetNameAndUnitFromSkuName wrong, name:%s, unit:%s", name, unit)
}
name, unit = GetNameAndUnitFromSkuName("【满59免运】蒜苔肉丝约400g")
if name != "【满59免运】蒜苔肉丝约400g" || unit != "份" {
t.Fatalf("TestGetNameAndUnitFromSkuName wrong, name:%s, unit:%s", name, unit)
}
}
func TestSplitSkuName(t *testing.T) {
prefix, name, comment, specUnit, unit, specQuality := SplitSkuName("[好吃]黄骨鱼约600G/非份(黄辣丁、昂刺鱼)")
if prefix != "好吃" || name != "黄骨鱼" || comment != "黄辣丁、昂刺鱼" || specUnit != "g" || unit != "非份" || specQuality != 600 {
t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit)
}
prefix, name, comment, specUnit, unit, specQuality = SplitSkuName("【满59免运】蒜苔肉丝约400g")
if prefix != "满59免运" || name != "蒜苔肉丝" || comment != "" || specUnit != "g" || unit != "份" || specQuality != 400 {
t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit)
}
prefix, name, comment, specUnit, unit, specQuality = SplitSkuName("【满59免运】蒜苔肉丝约400.1ML/")
if prefix != "满59免运" || name != "蒜苔肉丝" || comment != "" || specUnit != "ml" || unit != "份" || specQuality != 400.1 {
t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit)
}
}