41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestConvertKilometerMark(t *testing.T) {
|
|
// 1. 配置公里标转换关系
|
|
km1 := NewKilometerMark("YDK", 0)
|
|
km2 := NewKilometerMark("ZDK", 200)
|
|
kmc1 := NewKilometerMarkConverter(km1, km2, true)
|
|
t.Log(kmc1.Debug())
|
|
kmc2 := *NewKilometerMarkConverter(km1, km2, false)
|
|
t.Log(kmc2.Debug())
|
|
|
|
// 2. 验证公里标转换关系
|
|
tests := []struct {
|
|
km *KilometerMark
|
|
coordinate string
|
|
expect1 int64
|
|
expect2 int64
|
|
}{
|
|
{km: NewKilometerMark("YDK", 0), coordinate: km2.Coordinate(), expect1: 200, expect2: 200},
|
|
{km: NewKilometerMark("YDK", 100), coordinate: km2.Coordinate(), expect1: 300, expect2: 100},
|
|
{km: NewKilometerMark("YDK", -100), coordinate: km2.Coordinate(), expect1: 100, expect2: 300},
|
|
{km: NewKilometerMark("ZDK", 200), coordinate: km1.Coordinate(), expect1: 0, expect2: 0},
|
|
{km: NewKilometerMark("ZDK", 300), coordinate: km1.Coordinate(), expect1: 100, expect2: -100},
|
|
{km: NewKilometerMark("ZDK", 100), coordinate: km1.Coordinate(), expect1: -100, expect2: 100},
|
|
}
|
|
for _, test := range tests {
|
|
result1 := kmc1.Convert(test.km, test.coordinate)
|
|
if result1 != test.expect1 {
|
|
t.Errorf("expect1: %d, but got: %d", test.expect1, result1)
|
|
}
|
|
result2 := kmc2.Convert(test.km, test.coordinate)
|
|
if result2 != test.expect2 {
|
|
t.Errorf("expect2: %d, but got: %d", test.expect2, result2)
|
|
}
|
|
}
|
|
}
|