2024-04-07 20:59:41 +01:00
|
|
|
package cif
|
|
|
|
|
2024-04-08 11:44:36 +01:00
|
|
|
import (
|
2024-04-08 19:33:00 +01:00
|
|
|
"reflect"
|
2024-04-08 11:44:36 +01:00
|
|
|
"testing"
|
|
|
|
|
2024-04-08 19:33:00 +01:00
|
|
|
"git.fjla.uk/owlboard/go-types/pkg/database"
|
2024-04-08 11:44:36 +01:00
|
|
|
"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 {
|
2024-04-08 21:08:07 +01:00
|
|
|
input string
|
|
|
|
headcode string
|
|
|
|
expect bool
|
2024-04-08 11:44:36 +01:00
|
|
|
}{
|
2024-04-08 21:08:07 +01:00
|
|
|
{"", "1A00", true},
|
|
|
|
{"B", "2A05", true},
|
|
|
|
{"S", "1C99", false},
|
|
|
|
{"", "3C23", false},
|
|
|
|
{"", "5Q21", false},
|
|
|
|
{"", "5D32", false},
|
|
|
|
{"", "9O12", true},
|
|
|
|
{"B", "9D32", true},
|
|
|
|
{"", "7R43", false},
|
|
|
|
{"B", "6Y77", false},
|
|
|
|
{"", "8P98", false},
|
|
|
|
{"S", "4O89", false},
|
|
|
|
{"", "4E43", false},
|
2024-04-08 11:44:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2024-04-08 21:08:07 +01:00
|
|
|
result := hasFirstClass(&tc.input, &tc.headcode)
|
2024-04-08 11:44:36 +01:00
|
|
|
|
|
|
|
if result != tc.expect {
|
2024-04-08 21:08:07 +01:00
|
|
|
t.Errorf("For %s & headcode %s, expected %t, but got %t", tc.input, tc.headcode, tc.expect, result)
|
2024-04-08 11:44:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-08 21:08:07 +01:00
|
|
|
nilResult := hasFirstClass(nil, nil)
|
2024-04-08 11:44:36 +01:00
|
|
|
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
|
|
|
}
|
2024-04-08 19:33:00 +01:00
|
|
|
|
|
|
|
func TestParseStops(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
input []upstreamApi.CifScheduleLocation
|
|
|
|
expected []database.Stop
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
input: []upstreamApi.CifScheduleLocation{
|
|
|
|
{
|
|
|
|
LocationType: "LO",
|
|
|
|
RecordIdentity: "Yes",
|
|
|
|
TiplocCode: "BATHSPA",
|
|
|
|
TiplocInstance: "0",
|
|
|
|
Arrival: "0445",
|
|
|
|
Departure: "0449",
|
|
|
|
PublicDeparture: "0449",
|
|
|
|
Pass: "",
|
|
|
|
Platform: "1",
|
|
|
|
Line: "DM",
|
|
|
|
Path: "DM",
|
|
|
|
EngineeringAllowance: "",
|
|
|
|
PathingAllowance: "",
|
|
|
|
PerformanceAllowance: "",
|
|
|
|
}},
|
|
|
|
expected: []database.Stop{
|
|
|
|
{
|
|
|
|
PublicDeparture: "0449",
|
|
|
|
WttDeparture: "0449",
|
|
|
|
PublicArrival: "",
|
|
|
|
WttArrival: "0445",
|
|
|
|
IsPublic: true,
|
|
|
|
Tiploc: "BATHSPA",
|
|
|
|
Pass: "",
|
|
|
|
Platform: "1",
|
|
|
|
ArrLine: "DM",
|
|
|
|
DepLine: "DM",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
result := parseStops(&tc.input)
|
|
|
|
if !reflect.DeepEqual(result, tc.expected) {
|
|
|
|
t.Errorf("Test case failed. Input: %v, Expected: %v, Got: %v", tc.input, tc.expected, result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|