This commit is contained in:
2025-11-15 17:53:50 +01:00
parent 1bebded484
commit 5dc296805a
15 changed files with 634 additions and 688 deletions

View File

@@ -5,6 +5,7 @@ import (
"time"
"git.tornberg.me/go-gtfs/pkg/reader"
"git.tornberg.me/go-gtfs/pkg/types"
)
var tripData *reader.TripData
@@ -23,35 +24,68 @@ func TestFindRouteToStockholm(t *testing.T) {
//tp.Preprocess()
route, err := tp.FindRoute("740000030", "740000001", time.Now().Add(time.Hour*-16))
routes, err := tp.FindRoute("740000030", "740000001", time.Now())
if err != nil {
t.Fatalf("Error finding route: %v", err)
}
if route == nil {
if len(routes) == 0 {
t.Fatal("No route found from Falun Centralstation to Stockholm Centralstation")
}
if len(route.Legs) < 1 {
if len(routes[0].Legs) < 1 {
t.Fatal("Route has no legs")
}
}
func TestFindRouteWithRequiredChanges(t *testing.T) {
tp := NewTripPlanner(tripData)
//tp.Preprocess()
routes, err := tp.FindRoute("740000030", "740010947", time.Now().Add(time.Hour*-4))
if err != nil {
t.Fatalf("Error finding route: %v", err)
}
if len(routes) == 0 {
t.Fatal("No route found from Falun Centralstation to Uppsala Centralstation")
}
if len(routes[0].Legs) < 2 {
t.Fatal("Route has less than 2 legs, expected at least one transfer")
}
}
func TestFindRouteToMalmo(t *testing.T) {
tp := NewTripPlanner(tripData)
//tp.Preprocess()
route, err := tp.FindRoute("740000030", "740000003", time.Now().Add(time.Hour*-16))
routes, err := tp.FindRoute("740000030", "740000003", time.Now().Add(time.Hour*-8))
if err != nil {
t.Fatalf("Error finding route: %v", err)
}
if route == nil {
if len(routes) == 0 {
t.Fatal("No route found from Falun Centralstation to Malmö Centralstation")
}
if len(route.Legs) < 1 {
if len(routes[0].Legs) < 1 {
t.Fatal("Route has no legs")
}
}
func TestDepartuesAfter(t *testing.T) {
if hosjo, ok := tripData.Stops["740025287"]; ok {
trips := hosjo.GetTripsAfter(time.Now())
p := 3
for trip := range trips {
t.Logf("Trip %s (%s):", trip.TripShortName, trip.TripHeadsign)
for stop := range trip.GetDirectPossibleDestinations(hosjo, time.Now()) {
t.Logf("- Stop %s at %s", stop.Stop.StopName, types.AsTime(stop.DepartureTime))
}
p--
if p == 0 {
break
}
}
}
}