2024-04-07 20:59:41 +01:00
|
|
|
package cif
|
|
|
|
|
2024-04-08 11:44:36 +01:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
|
|
|
|
)
|
2024-04-07 20:59:41 +01:00
|
|
|
|
|
|
|
func TestParseSpeed(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2024-04-07 21:28:48 +01:00
|
|
|
input string
|
2024-04-07 20:59:41 +01:00
|
|
|
expected int32
|
|
|
|
}{
|
2024-04-07 21:28:48 +01:00
|
|
|
{"075", 75},
|
|
|
|
{"125", 125},
|
|
|
|
{"40", 40},
|
|
|
|
{"040", 40},
|
|
|
|
{"134", 60},
|
|
|
|
{"179", 80},
|
|
|
|
{"186", 186},
|
|
|
|
{"417", 186},
|
2024-04-07 20:59:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2024-04-07 21:28:48 +01:00
|
|
|
result := parseSpeed(&tc.input)
|
2024-04-07 20:59:41 +01:00
|
|
|
|
|
|
|
if result != tc.expected {
|
|
|
|
t.Errorf("For speed: %s, expected: %d, but got: %d", tc.input, tc.expected, result)
|
|
|
|
}
|
|
|
|
}
|
2024-04-08 11:44:36 +01:00
|
|
|
|
|
|
|
nilResult := parseSpeed(nil)
|
|
|
|
if nilResult != 0 {
|
|
|
|
t.Errorf("parseSpeed failed to handle nil pointer, expected %d, but got %d", 0, nilResult)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsPublic(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
input upstreamApi.CifScheduleLocation
|
|
|
|
expect bool
|
|
|
|
}{
|
|
|
|
{upstreamApi.CifScheduleLocation{
|
|
|
|
LocationType: "LO",
|
|
|
|
RecordIdentity: "",
|
|
|
|
TiplocCode: "BATHSPA",
|
|
|
|
TiplocInstance: "0",
|
|
|
|
Arrival: "0422H",
|
|
|
|
Departure: "0445",
|
|
|
|
PublicDeparture: "0445",
|
|
|
|
Pass: "",
|
|
|
|
Path: "UFR",
|
|
|
|
Platform: "1",
|
|
|
|
Line: "DFR",
|
|
|
|
EngineeringAllowance: "",
|
|
|
|
PathingAllowance: "",
|
|
|
|
PerformanceAllowance: "",
|
|
|
|
}, true},
|
|
|
|
{upstreamApi.CifScheduleLocation{
|
|
|
|
LocationType: "LO",
|
|
|
|
RecordIdentity: "",
|
|
|
|
TiplocCode: "BATHSPA",
|
|
|
|
TiplocInstance: "0",
|
|
|
|
Arrival: "0422H",
|
|
|
|
Departure: "0445",
|
|
|
|
PublicDeparture: "",
|
|
|
|
Pass: "",
|
|
|
|
Path: "UFR",
|
|
|
|
Platform: "1",
|
|
|
|
Line: "DFR",
|
|
|
|
EngineeringAllowance: "",
|
|
|
|
PathingAllowance: "",
|
|
|
|
PerformanceAllowance: "",
|
|
|
|
}, false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for num, tc := range testCases {
|
|
|
|
result := isPublic(&tc.input)
|
|
|
|
|
|
|
|
if result != tc.expect {
|
|
|
|
t.Errorf("For testCase %d, expected %t, but got %t", num, tc.expect, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHasFirstClass(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
input string
|
|
|
|
expect bool
|
|
|
|
}{
|
|
|
|
{"", true},
|
|
|
|
{"B", true},
|
|
|
|
{"S", false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
result := hasFirstClass(&tc.input)
|
|
|
|
|
|
|
|
if result != tc.expect {
|
|
|
|
t.Errorf("For %s, expected %t, but got %t", tc.input, tc.expect, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nilResult := hasFirstClass(nil)
|
|
|
|
if nilResult {
|
|
|
|
t.Errorf("hasFirstClass failed to handle nil pointer, expected %t, got %t", false, nilResult)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHasCatering(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
input string
|
|
|
|
expect bool
|
|
|
|
}{
|
|
|
|
{"", false},
|
|
|
|
{"CF", true},
|
|
|
|
{"HT", true},
|
|
|
|
{"MR", true},
|
|
|
|
{"RP", true},
|
|
|
|
{"T", true},
|
|
|
|
{"F", true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
result := hasCatering(&tc.input)
|
|
|
|
|
|
|
|
if result != tc.expect {
|
|
|
|
t.Errorf("For %s, expected %t, but got %t", tc.input, tc.expect, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nilResult := hasCatering(nil)
|
|
|
|
if nilResult {
|
|
|
|
t.Errorf("hasCatering failed to handle nil pointer, expected %t, but got %t", false, nilResult)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHasSleeper(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
input string
|
|
|
|
expect bool
|
|
|
|
}{
|
|
|
|
{"B", true},
|
|
|
|
{"F", true},
|
|
|
|
{"S", true},
|
|
|
|
{"", false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
result := hasSleeper(&tc.input)
|
|
|
|
|
|
|
|
if result != tc.expect {
|
|
|
|
t.Errorf("For %s, expected %t, but got %t", tc.input, tc.expect, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nilResult := hasSleeper(nil)
|
|
|
|
if nilResult {
|
|
|
|
t.Errorf("hasSleeper failed to handle nil pointer, expected %t, but got %t", false, nilResult)
|
|
|
|
}
|
2024-04-07 20:59:41 +01:00
|
|
|
}
|