some custom stuff
This commit is contained in:
@@ -1,26 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.tornberg.me/go-gtfs/pkg/reader"
|
||||
)
|
||||
|
||||
func TestFindRoute(t *testing.T) {
|
||||
os.Chdir("../..")
|
||||
tp := NewTripPlanner()
|
||||
var tripData *reader.TripData
|
||||
|
||||
err := tp.LoadData("data")
|
||||
func init() {
|
||||
var err error
|
||||
tripData, err = reader.LoadTripData("../../data")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to load data: %v", err)
|
||||
panic("Failed to load trip data: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
err = tp.Preprocess()
|
||||
func TestFindRouteToStockholm(t *testing.T) {
|
||||
|
||||
tp := NewTripPlanner(tripData)
|
||||
|
||||
//tp.Preprocess()
|
||||
|
||||
route, err := tp.FindRoute("740000030", "740000001", time.Now().Add(time.Hour*-16))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to preprocess: %v", err)
|
||||
t.Fatalf("Error finding route: %v", err)
|
||||
}
|
||||
|
||||
route := tp.FindRoute("740000030", "740000001", time.Now())
|
||||
if route == nil {
|
||||
t.Fatal("No route found from Falun Centralstation to Stockholm Centralstation")
|
||||
}
|
||||
@@ -29,50 +35,17 @@ func TestFindRoute(t *testing.T) {
|
||||
t.Fatal("Route has no legs")
|
||||
}
|
||||
|
||||
stops := []string{}
|
||||
if len(route.Legs) > 0 {
|
||||
stops = append(stops, route.Legs[0].From)
|
||||
for _, leg := range route.Legs {
|
||||
stops = append(stops, leg.To)
|
||||
}
|
||||
}
|
||||
|
||||
if len(stops) < 2 {
|
||||
t.Fatal("Route path is too short")
|
||||
}
|
||||
|
||||
if stops[0] != "740000030" {
|
||||
t.Errorf("Route does not start at Falun Centralstation (740000030), starts at %s", stops[0])
|
||||
}
|
||||
|
||||
if stops[len(stops)-1] != "740000001" {
|
||||
t.Errorf("Route does not end at Stockholm Centralstation (740000001), ends at %s", stops[len(stops)-1])
|
||||
}
|
||||
|
||||
// Additional check: ensure all stops in path exist
|
||||
for _, stopID := range stops {
|
||||
if s, exists := tp.stops[stopID]; !exists {
|
||||
t.Errorf("Stop %s in path does not exist", stopID)
|
||||
} else {
|
||||
t.Logf("stop: %s", s.StopName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindRouteToMalmo(t *testing.T) {
|
||||
tp := NewTripPlanner()
|
||||
tp := NewTripPlanner(tripData)
|
||||
|
||||
err := tp.LoadData("data")
|
||||
//tp.Preprocess()
|
||||
|
||||
route, err := tp.FindRoute("740000030", "740000003", time.Now().Add(time.Hour*-16))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to load data: %v", err)
|
||||
t.Fatalf("Error finding route: %v", err)
|
||||
}
|
||||
|
||||
err = tp.Preprocess()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to preprocess: %v", err)
|
||||
}
|
||||
|
||||
route := tp.FindRoute("740000030", "740000003", time.Now())
|
||||
if route == nil {
|
||||
t.Fatal("No route found from Falun Centralstation to Malmö Centralstation")
|
||||
}
|
||||
@@ -81,30 +54,4 @@ func TestFindRouteToMalmo(t *testing.T) {
|
||||
t.Fatal("Route has no legs")
|
||||
}
|
||||
|
||||
stops := []string{}
|
||||
if len(route.Legs) > 0 {
|
||||
stops = append(stops, route.Legs[0].From)
|
||||
for _, leg := range route.Legs {
|
||||
stops = append(stops, leg.To)
|
||||
}
|
||||
}
|
||||
|
||||
if len(stops) < 2 {
|
||||
t.Fatal("Route path is too short")
|
||||
}
|
||||
|
||||
if stops[0] != "740000030" {
|
||||
t.Errorf("Route does not start at Falun Centralstation (740000030), starts at %s", stops[0])
|
||||
}
|
||||
|
||||
if stops[len(stops)-1] != "740000003" {
|
||||
t.Errorf("Route does not end at Malmö Centralstation (740000003), ends at %s", stops[len(stops)-1])
|
||||
}
|
||||
|
||||
// Additional check: ensure all stops in path exist
|
||||
for _, stopID := range stops {
|
||||
if _, exists := tp.stops[stopID]; !exists {
|
||||
t.Errorf("Stop %s in path does not exist", stopID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user