rts-sim-testing-service/third_party/deprecated/http_test.go

103 lines
2.0 KiB
Go
Raw Normal View History

package dynamics
import (
"encoding/json"
"testing"
"time"
"github.com/spf13/viper"
"joylink.club/bj-rtsts-server/config"
)
func TestSendTrainInitReq(t *testing.T) {
viper.AddConfigPath("../")
config.LoadConfig()
info := InitTrainInfo{
TrainIndex: uint16(1),
LinkIndex: 2,
LinkOffset: 3,
Speed: 4,
Up: true,
}
time.Sleep(time.Second)
SendInitTrainReq(&info)
}
func TestSendSimulationStartReq(t *testing.T) {
viper.AddConfigPath("../")
config.LoadConfig()
SendSimulationStartReq(mockLineBaseInfo())
}
func TestSendSimulationEndReq(t *testing.T) {
viper.AddConfigPath("../")
config.LoadConfig()
SendSimulationEndReq()
}
func mockLineBaseInfo() *LineBaseInfo {
var links []*Link
for i := 1; i <= 12; i++ {
var atid int32
var btid int32
if i <= 6 {
atid = int32(i - 1)
btid = int32(i)
} else {
atid = int32(i - 2)
btid = int32(i - 1)
}
if i == 1 || i == 7 {
atid = 0
} else if i == 6 || i == 12 {
btid = 0
}
links = append(links, &Link{
ID: int32(i),
Len: int32(i * 100000),
ARelTurnoutId: atid,
ARelTurnoutPoint: "A",
BRelTurnoutId: btid,
BRelTurnoutPoint: "B",
})
}
for i := 13; i <= 17; i++ {
links = append(links, &Link{
ID: int32(i),
Len: int32(i * 100000),
ARelTurnoutId: int32(i - 12),
ARelTurnoutPoint: "A",
BRelTurnoutId: int32(i - 12 + 5),
BRelTurnoutPoint: "B",
})
}
slopes := []*Slope{{
ID: 1,
StartLinkId: 1,
StartLinkOffset: 1,
EndLinkId: 1,
EndLinkOffset: 1,
DegreeTrig: 1,
}}
curves := []*Curve{{
ID: 1,
StartLinkId: 1,
StartLinkOffset: 1,
EndLinkId: 1,
EndLinkOffset: 1,
Curvature: 1,
}}
base := LineBaseInfo{
LinkList: links,
SlopeList: slopes,
CurveList: curves,
}
return &base
}
func TestCalculationBase(t *testing.T) {
base := mockLineBaseInfo()
marshal, _ := json.Marshal(base)
println(string(marshal))
}