47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
|
package repo_test
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"joylink.club/rtss-core/model"
|
||
|
"joylink.club/rtss-core/repo"
|
||
|
)
|
||
|
|
||
|
func TestRepositoryConvertKilometerMark(t *testing.T) {
|
||
|
// 1. 配置公里标转换关系
|
||
|
km1 := model.NewKilometerMark("YDK", 0)
|
||
|
km2 := model.NewKilometerMark("ZDK", 200)
|
||
|
kmc1 := model.NewKilometerMarkConverter(km1, km2, true)
|
||
|
t.Log(kmc1.Debug())
|
||
|
repo1 := repo.NewRepo("Test")
|
||
|
repo1.KilometerMarkConverters = append(repo1.KilometerMarkConverters, kmc1)
|
||
|
|
||
|
// 2. 验证公里标转换关系
|
||
|
tests := []struct {
|
||
|
km *model.KilometerMark
|
||
|
targetCoordinate string
|
||
|
expect int64
|
||
|
expectError bool
|
||
|
}{
|
||
|
{km: model.NewKilometerMark("YDK", 0), targetCoordinate: km2.Coordinate(), expect: 200, expectError: false},
|
||
|
{km: model.NewKilometerMark("ZDK", 0), targetCoordinate: km1.Coordinate(), expect: -200, expectError: false},
|
||
|
{km: model.NewKilometerMark("YDK", 100), targetCoordinate: "Other", expect: 0, expectError: true},
|
||
|
}
|
||
|
t.Logf("tests: %v", tests)
|
||
|
for _, test := range tests {
|
||
|
result, err := repo1.ConvertKilometerMark(test.km, test.targetCoordinate)
|
||
|
if test.expectError {
|
||
|
if err == nil {
|
||
|
t.Errorf("expect error, but got nil")
|
||
|
}
|
||
|
} else {
|
||
|
if err != nil {
|
||
|
t.Errorf("expect %d, but got error: %v", test.expect, err)
|
||
|
}
|
||
|
if result != test.expect {
|
||
|
t.Errorf("expect: %d, but got: %d", test.expect, result)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|