Skip to content

Commit

Permalink
TEST: NAV-40 - Add tests for same station transfer times in raptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
clukas1 committed Jun 7, 2024
1 parent 521e088 commit 66347c8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/main/java/ch/naviqore/raptor/Stop.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package ch.naviqore.raptor;

record Stop(String id, int stopRouteIdx, int numberOfRoutes, int sameStationTransferTime, int transferIdx, int numberOfTransfers) {
record Stop(String id, int stopRouteIdx, int numberOfRoutes, int sameStationTransferTime, int transferIdx,
int numberOfTransfers) {
}
37 changes: 30 additions & 7 deletions src/test/java/ch/naviqore/raptor/RaptorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ void shouldTakeFirstTripWithoutAddingSameStationTransferTime(RaptorTestBuilder b

@Test
void shouldMissConnectingTripBecauseOfSameStationTransferTime(RaptorTestBuilder builder) {
Raptor raptor = builder.withAddRoute1_AG(19, 15, 5, 1).withAddRoute2_HL().build();
// TODO: Adjust when same station transfers are stop specific
Raptor raptor = builder.withAddRoute1_AG(19, 15, 5, 1)
.withAddRoute2_HL()
.withSameStationTransferTime(120)
.build();
// There should be a connection leaving stop A at 5:19 am and arriving at stop B at 5:24 am
// Connection at 5:24 from B to C should be missed because of the same station transfer time (120s)
String sourceStop = "A";
Expand All @@ -284,9 +286,29 @@ void shouldMissConnectingTripBecauseOfSameStationTransferTime(RaptorTestBuilder
}

@Test
void shouldCatchConnectingTripBecauseWithSameStationTransferTime(RaptorTestBuilder builder) {
Raptor raptor = builder.withAddRoute1_AG(17, 15, 5, 1).withAddRoute2_HL().build();
// TODO: Adjust when same station transfers are stop specific
void shouldCatchConnectingTripBecauseOfNoSameStationTransferTime(RaptorTestBuilder builder) {
Raptor raptor = builder.withAddRoute1_AG(19, 15, 5, 1)
.withAddRoute2_HL()
.withSameStationTransferTime(0)
.build();
// There should be a connection leaving stop A at 5:19 am and arriving at stop B at 5:24 am
// Connection at 5:24 from B to C should not be missed because of no same station transfer time
String sourceStop = "A";
String targetStop = "H";
int departureTime = 5 * RaptorTestBuilder.SECONDS_IN_HOUR;
List<Connection> connections = raptor.routeEarliestArrival(sourceStop, targetStop, departureTime);

assertEquals(1, connections.size());
assertEquals(departureTime + 19 * 60, connections.getFirst().getDepartureTime());
assertEquals(departureTime + 24 * 60, connections.getFirst().getLegs().get(1).departureTime());
}

@Test
void shouldCatchConnectingTripWithSameStationTransferTime(RaptorTestBuilder builder) {
Raptor raptor = builder.withAddRoute1_AG(17, 15, 5, 1)
.withAddRoute2_HL()
.withSameStationTransferTime(120)
.build();
// There should be a connection leaving stop A at 5:17 am and arriving at stop B at 5:22 am
// Connection at 5:24 from B to C should be cached when the same station transfer time is 120s
String sourceStop = "A";
Expand Down Expand Up @@ -362,8 +384,9 @@ void shouldCreateIsoLinesFromTwoNotConnectedSourceStops(RaptorTestBuilder builde
Map<String, Integer> departureTimeHours = Map.of("A", 8, "M", 16);

List<String> reachableStopsFromStopA = List.of("B", "C", "D", "E", "F", "G");
Map<String, Integer> sourceStops = Map.of("A", departureTimeHours.get("A") * RaptorTestBuilder.SECONDS_IN_HOUR,
"M", departureTimeHours.get("M") * RaptorTestBuilder.SECONDS_IN_HOUR);
Map<String, Integer> sourceStops = Map.of("A",
departureTimeHours.get("A") * RaptorTestBuilder.SECONDS_IN_HOUR, "M",
departureTimeHours.get("M") * RaptorTestBuilder.SECONDS_IN_HOUR);
List<String> reachableStopsFromStopM = List.of("K", "N", "O", "P", "Q");

Map<String, Connection> isoLines = raptor.getIsoLines(sourceStops);
Expand Down
14 changes: 10 additions & 4 deletions src/test/java/ch/naviqore/raptor/RaptorTestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ public class RaptorTestBuilder {
static final int SECONDS_IN_HOUR = 3600;
private static final int DAY_START_HOUR = 5;
private static final int DAY_END_HOUR = 25;

private final List<Route> routes = new ArrayList<>();
private final List<Transfer> transfers = new ArrayList<>();
private int sameStationTransferTime = 120;

private static Raptor build(List<Route> routes, List<Transfer> transfers, int dayStart, int dayEnd) {
RaptorBuilder builder = Raptor.builder();
private static Raptor build(List<Route> routes, List<Transfer> transfers, int dayStart, int dayEnd,
int sameStationTransferTime) {
RaptorBuilder builder = Raptor.builder(sameStationTransferTime);
Set<String> addedStops = new HashSet<>();

for (Route route : routes) {
Expand Down Expand Up @@ -157,8 +158,13 @@ public RaptorTestBuilder withAddTransfer2_LR() {
return this;
}

public RaptorTestBuilder withSameStationTransferTime(int sameStationTransferTime) {
this.sameStationTransferTime = sameStationTransferTime;
return this;
}

public Raptor build() {
return build(routes, transfers, DAY_START_HOUR, DAY_END_HOUR);
return build(routes, transfers, DAY_START_HOUR, DAY_END_HOUR, sameStationTransferTime);
}

public Raptor buildWithDefaults() {
Expand Down

0 comments on commit 66347c8

Please sign in to comment.