2024-07-04 20:16:10 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConvertKilometerMark(t *testing.T) {
|
|
|
|
// 1. 配置公里标转换关系
|
2024-07-10 18:09:16 +08:00
|
|
|
km1 := NewKilometerMark("YDK", 0)
|
|
|
|
km2 := NewKilometerMark("ZDK", 200)
|
|
|
|
kmc1 := NewKilometerMarkConverter(km1, km2, true)
|
2024-07-04 20:16:10 +08:00
|
|
|
t.Log(kmc1.Debug())
|
2024-07-10 18:09:16 +08:00
|
|
|
kmc2 := *NewKilometerMarkConverter(km1, km2, false)
|
2024-07-04 20:16:10 +08:00
|
|
|
t.Log(kmc2.Debug())
|
|
|
|
|
|
|
|
// 2. 验证公里标转换关系
|
|
|
|
tests := []struct {
|
|
|
|
km *KilometerMark
|
|
|
|
coordinate string
|
|
|
|
expect1 int64
|
|
|
|
expect2 int64
|
|
|
|
}{
|
2024-07-10 18:09:16 +08:00
|
|
|
{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},
|
2024-07-04 20:16:10 +08:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|