Begin parsing of JsonSchedule

This commit is contained in:
Fred Boniface
2024-04-07 21:28:48 +01:00
parent 4a7bcd7f80
commit 84b7d42898
4 changed files with 40 additions and 15 deletions

View File

@@ -49,7 +49,34 @@ func parseSpeed(CIFSpeed *string) int32 {
return int32(speed)
}
// Not tested
func parseStops(input *[]upstreamApi.CifScheduleLocation) []database.Stop {
output := make([]database.Stop, 0, len(*input))
for _, item := range *input {
stop := database.Stop{
PublicDeparture: item.PublicDeparture,
PublicArrival: item.PublicArrival,
WttDeparture: item.Departure,
WttArrival: item.Arrival,
Pass: item.Pass,
Platform: item.Platform,
ArrLine: item.Path,
DepLine: item.Line,
Tiploc: item.TiplocCode,
IsPublic: isPublic(&item),
}
output = append(output, stop)
}
return output
}
// Not tested
func isPublic(input *upstreamApi.CifScheduleLocation) bool {
if input.PublicArrival == "" && input.PublicDeparture == "" {
return false
}
return true
}

View File

@@ -4,28 +4,24 @@ import "testing"
func TestParseSpeed(t *testing.T) {
testCases := []struct {
input *string
input string
expected int32
}{
{strPtr("075"), 75},
{strPtr("125"), 125},
{strPtr("40"), 40},
{strPtr("040"), 40},
{strPtr("134"), 60},
{strPtr("179"), 80},
{strPtr("186"), 186},
{strPtr("417"), 186},
{"075", 75},
{"125", 125},
{"40", 40},
{"040", 40},
{"134", 60},
{"179", 80},
{"186", 186},
{"417", 186},
}
for _, tc := range testCases {
result := parseSpeed(tc.input)
result := parseSpeed(&tc.input)
if result != tc.expected {
t.Errorf("For speed: %s, expected: %d, but got: %d", tc.input, tc.expected, result)
}
}
}
func strPtr(s string) *string {
return &s
}