92 lines
2.0 KiB
Go
92 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.tornberg.me/go-gtfs/pkg/reader"
|
|
"git.tornberg.me/go-gtfs/pkg/types"
|
|
)
|
|
|
|
var tripData *reader.TripData
|
|
|
|
func init() {
|
|
var err error
|
|
tripData, err = reader.LoadTripData("../../data")
|
|
if err != nil {
|
|
panic("Failed to load trip data: " + err.Error())
|
|
}
|
|
}
|
|
|
|
func TestFindRouteToStockholm(t *testing.T) {
|
|
|
|
tp := NewTripPlanner(tripData)
|
|
|
|
//tp.Preprocess()
|
|
|
|
routes, err := tp.FindRoute("740000030", "740000001", time.Now())
|
|
if err != nil {
|
|
t.Fatalf("Error finding route: %v", err)
|
|
}
|
|
if len(routes) == 0 {
|
|
t.Fatal("No route found from Falun Centralstation to Stockholm Centralstation")
|
|
}
|
|
|
|
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()
|
|
|
|
routes, err := tp.FindRoute("740000030", "740000003", time.Now().Add(time.Hour*-8))
|
|
if err != nil {
|
|
t.Fatalf("Error finding route: %v", err)
|
|
}
|
|
if len(routes) == 0 {
|
|
t.Fatal("No route found from Falun Centralstation to Malmö Centralstation")
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|