49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
|
package model
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestConvertKilometerMark(t *testing.T) {
|
||
|
// 1. 配置公里标转换关系
|
||
|
km1 := NewKilometerMark("DBCSK", OperationDirectionUp, 0)
|
||
|
km2 := NewKilometerMark("DCSK", OperationDirectionUp, 200)
|
||
|
kmc1 := &KilometerMarkConverter{
|
||
|
km1: *km1,
|
||
|
km2: *km2,
|
||
|
trendSame: true,
|
||
|
}
|
||
|
t.Log(kmc1.Debug())
|
||
|
kmc2 := &KilometerMarkConverter{
|
||
|
km1: *km1,
|
||
|
km2: *km2,
|
||
|
trendSame: false,
|
||
|
}
|
||
|
t.Log(kmc2.Debug())
|
||
|
|
||
|
// 2. 验证公里标转换关系
|
||
|
tests := []struct {
|
||
|
km *KilometerMark
|
||
|
coordinate string
|
||
|
expect1 int64
|
||
|
expect2 int64
|
||
|
}{
|
||
|
{km: NewKilometerMark("DBCSK", OperationDirectionUp, 0), coordinate: km2.Coordinate(), expect1: 200, expect2: 200},
|
||
|
{km: NewKilometerMark("DBCSK", OperationDirectionUp, 100), coordinate: km2.Coordinate(), expect1: 300, expect2: 100},
|
||
|
{km: NewKilometerMark("DBCSK", OperationDirectionUp, -100), coordinate: km2.Coordinate(), expect1: 100, expect2: 300},
|
||
|
{km: NewKilometerMark("DCSK", OperationDirectionUp, 200), coordinate: km1.Coordinate(), expect1: 0, expect2: 0},
|
||
|
{km: NewKilometerMark("DCSK", OperationDirectionUp, 300), coordinate: km1.Coordinate(), expect1: 100, expect2: -100},
|
||
|
{km: NewKilometerMark("DCSK", OperationDirectionUp, 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)
|
||
|
}
|
||
|
}
|
||
|
}
|