Skip to content

Commit

Permalink
TEST: #181 - Add tests for service showing that geo routing does not …
Browse files Browse the repository at this point in the history
…allow source and target transfers from raptor.
  • Loading branch information
clukas1 committed Feb 15, 2025
1 parent 3784c80 commit 07bc43e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,23 @@ private void setup() {
builder.addStop("C", "C", 0.0, 2.0);
builder.addStop("C1", "C1", 0.001, 2.0, "C", AccessibilityInformation.UNKNOWN);
builder.addStop("C2", "C2", -0.001, 2.0, "C", AccessibilityInformation.UNKNOWN);
// D, D1 and D2 are more than 500 m apart!
builder.addStop("D", "D", 0.0, 3.0);
builder.addStop("D1", "D1", 0.001, 3.0, "D", AccessibilityInformation.UNKNOWN);
builder.addStop("D2", "D2", -0.001, 3.0, "D", AccessibilityInformation.UNKNOWN);
builder.addStop("D1", "D1", 0.005, 3.0, "D", AccessibilityInformation.UNKNOWN);
builder.addStop("D2", "D2", -0.005, 3.0, "D", AccessibilityInformation.UNKNOWN);
builder.addStop("E", "E", 0.0, 4.0);

// Route 1 goes from A, B1, C1, D2
builder.addRoute("R1", "agency", "R1", "R1", RouteType.parse(1));
builder.addTrip("T1", "R1", "always", "C1");
builder.addTrip("T1", "R1", "always", "D1");
builder.addStopTime("T1", "A", new ServiceDayTime(60), new ServiceDayTime(120));
builder.addStopTime("T1", "B1", new ServiceDayTime(180), new ServiceDayTime(240));
builder.addStopTime("T1", "C1", new ServiceDayTime(301), new ServiceDayTime(360));
builder.addStopTime("T1", "D1", new ServiceDayTime(420), new ServiceDayTime(480));

// Route 2 goes from A, B2, C
builder.addRoute("R2", "agency", "R2", "R2", RouteType.parse(1));
builder.addTrip("T2", "R2", "always", "C");
builder.addTrip("T2", "R2", "always", "D2");
builder.addStopTime("T2", "A", new ServiceDayTime(60), new ServiceDayTime(120));
builder.addStopTime("T2", "B2", new ServiceDayTime(180), new ServiceDayTime(240));
builder.addStopTime("T2", "C", new ServiceDayTime(300), new ServiceDayTime(360));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static ch.naviqore.service.config.ServiceConfig.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
import static org.junit.jupiter.api.Assertions.assertTrue;

class RoutingQueryFacadeIT {

Expand Down Expand Up @@ -99,39 +100,52 @@ private Stop getStopById(String id) {
}

private void assertFirstMileWalk(Leg leg) {
assertFirstMileWalk(leg, sourceStop, sourceCoordinate);
}

private void assertFirstMileWalk(Leg leg, Stop stop, GeoCoordinate coordinate) {
assertThat(leg).isInstanceOf(Walk.class);
Walk walk = (Walk) leg;

assertThat(walk.getStop()).isPresent();
assertThat(walk.getStop().get().getId()).isEqualTo("A");
assertThat(walk.getStop().get().getId()).isEqualTo(stop.getId());

assertThat(walk.getSourceLocation().distanceTo(sourceCoordinate)).isCloseTo(0, within(EPSILON));
assertThat(walk.getTargetLocation().distanceTo(sourceStop.getCoordinate())).isCloseTo(0, within(EPSILON));
assertThat(walk.getSourceLocation().distanceTo(coordinate)).isCloseTo(0, within(EPSILON));
assertThat(walk.getTargetLocation().distanceTo(stop.getCoordinate())).isCloseTo(0, within(EPSILON));
}

@Nested
class Connections {

private static void assertPublicTransitLeg(Leg leg) {
assertPublicTransitLeg(leg, "A", "C", "T2", "R2");
}

private static void assertPublicTransitLeg(Leg leg, String departureStopId, String arrivalStopId, String tripId,
String routeId) {
assertThat(leg).isInstanceOf(PublicTransitLeg.class);
PublicTransitLeg publicTransitLeg = (PublicTransitLeg) leg;

assertThat(publicTransitLeg.getTrip().getId()).isEqualTo("T2");
assertThat(publicTransitLeg.getTrip().getRoute().getId()).isEqualTo("R2");
assertThat(publicTransitLeg.getTrip().getId()).isEqualTo(tripId);
assertThat(publicTransitLeg.getTrip().getRoute().getId()).isEqualTo(routeId);

assertThat(publicTransitLeg.getDeparture().getStop().getId()).isEqualTo("A");
assertThat(publicTransitLeg.getArrival().getStop().getId()).isEqualTo("C");
assertThat(publicTransitLeg.getDeparture().getStop().getId()).isEqualTo(departureStopId);
assertThat(publicTransitLeg.getArrival().getStop().getId()).isEqualTo(arrivalStopId);
}

private void assertLastMileWalk(Leg leg) {
assertLastMileWalk(leg, targetStop, targetCoordinate);
}

private void assertLastMileWalk(Leg leg, Stop stop, GeoCoordinate coordinate) {
assertThat(leg).isInstanceOf(Walk.class);
Walk walk = (Walk) leg;

assertThat(walk.getStop()).isPresent();
assertThat(walk.getStop().get().getId()).isEqualTo("C");
assertThat(walk.getStop().get().getId()).isEqualTo(stop.getId());

assertThat(walk.getSourceLocation().distanceTo(targetStop.getCoordinate())).isCloseTo(0, within(EPSILON));
assertThat(walk.getTargetLocation().distanceTo(targetCoordinate)).isCloseTo(0, within(EPSILON));
assertThat(walk.getSourceLocation().distanceTo(stop.getCoordinate())).isCloseTo(0, within(EPSILON));
assertThat(walk.getTargetLocation().distanceTo(coordinate)).isCloseTo(0, within(EPSILON));
}

@Nested
Expand Down Expand Up @@ -215,6 +229,29 @@ void arrival() throws ConnectionRoutingException {
assertPublicTransitLeg(legs.getFirst());
assertLastMileWalk(legs.get(1));
}

@Test
void departure_targetOutOfRange() throws ConnectionRoutingException {
// this is 440 m from C1 and 560 m from C away, which makes C1 in range of location search and C outside
// (range search looks within 500 m --> ServiceConfig.DEFAULT_WALKING_SEARCH_RADIUS)
GeoCoordinate targetCoordinate = new GeoCoordinate(0.005, 2.0);

// routing from B2 only connects to C and not C1 --> no connection possible
List<ch.naviqore.service.Connection> connections = facade.queryConnections(DATE_TIME,
TimeType.DEPARTURE, QUERY_CONFIG, getStopById("B2"), targetCoordinate);
assertThat(connections).hasSize(0);

// ensuring that an arrival at C1 allows reaching the target location --> routing B1 -> target
// (through C1)
connections = facade.queryConnections(DATE_TIME, TimeType.ARRIVAL, QUERY_CONFIG, getStopById("B1"),
targetCoordinate);
assertThat(connections).hasSize(1);
Connection connection = connections.getFirst();
assertThat(connection.getLegs()).hasSize(2);

assertPublicTransitLeg(connection.getLegs().getFirst(), "B1", "C1", "T1", "R1");
assertLastMileWalk(connection.getLegs().getLast(), getStopById("C1"), targetCoordinate);
}
}

@Nested
Expand Down Expand Up @@ -258,6 +295,34 @@ void arrival() throws ConnectionRoutingException {
assertPublicTransitLeg(legs.get(1));
}

@Test
void departure_sourceOutOfRange() throws ConnectionRoutingException {
// this is 440 m from B1 and 670 m from B2 away, which makes B1 in range of location search and B2
// outside (range search looks within 500 m --> ServiceConfig.DEFAULT_WALKING_SEARCH_RADIUS)
GeoCoordinate sourceCoordinate = new GeoCoordinate(0.005, 1.0);

// since walking to stop B1 will take ~5 minutes and this will miss the only trip of the day the default
// start time is set back by 5 minutes.
LocalDateTime startTime = DATE_TIME.minusMinutes(5);

// from source coordinate only departures from stop B1 (i.e. Route 1 going to D1) should be usable,
// routes departing from same stop complex at B2 (i.e. Route 2 going to D2) should be unusable.
List<Connection> connections = facade.queryConnections(startTime, TimeType.DEPARTURE, QUERY_CONFIG,
sourceCoordinate, getStopById("D1"));
assertThat(connections).hasSize(1);
Connection connection = connections.getFirst();
assertThat(connection.getLegs()).hasSize(2);

assertFirstMileWalk(connection.getLegs().getFirst(), getStopById("B1"), sourceCoordinate);
assertPublicTransitLeg(connection.getLegs().getLast(), "B1", "D1", "T1", "R1");

// when the original request to route to D2 fails, it will fall back to GeoToGeo coordinate routing,
// however since D1 and D2 are more than 500 m apart this will also fail.
connections = facade.queryConnections(startTime, TimeType.DEPARTURE, QUERY_CONFIG,
sourceCoordinate, getStopById("D2"));
assertThat(connections).hasSize(0);
}

}

@Nested
Expand Down

0 comments on commit 07bc43e

Please sign in to comment.