rtss-core/repo/repo_test.go
soul-walker 1a610c01ba 调整公里标概念,添加注释说明
完善道岔区段与道岔关系构建检查
添加Link位置和link范围工具类
完善example道岔区段关系构建
2024-07-10 18:09:16 +08:00

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)
}
}
}
}