Skip to content

Commit

Permalink
TEST: 158 - Adjust converter test
Browse files Browse the repository at this point in the history
Now only stops with departures are added to the raptor.
  • Loading branch information
munterfi committed Jan 10, 2025
1 parent 8dbf6aa commit 5d0d015
Showing 1 changed file with 24 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class ManualSchedule {
* <li><b>Route 1</b>: Passes through A - B1 - C1</li>
* <li><b>Route 2</b>: Passes through A - B2 - C</li>
* </ul>
* Stops B, C2 and D have no departures/arrivals. Stops B and C are parents of stops B1, B2 and C1, C2,
* respectively.
* Stops B, C2 and D have no departures/arrivals and should not be included in the raptor conversion.
* Stops B and C are parents of stops B1, B2 and C1, C2, respectively.
*/
static RaptorBuilderData convertRaptor(List<Transfer> scheduleTransfers,
List<Transfer> additionalTransfers) throws NoSuchFieldException, IllegalAccessException {
Expand Down Expand Up @@ -121,12 +121,12 @@ static RaptorBuilderData convertRaptor(List<Transfer> scheduleTransfers,
@Test
void noTransfers() throws NoSuchFieldException, IllegalAccessException {
RaptorBuilderData data = convertRaptor(List.of(), List.of());
Set<String> stopsWithDepartures = Set.of("A", "B1", "B2", "C", "C1");

data.assertStops(Set.of("A", "B", "B1", "B2", "C", "C1", "C2", "D"));
data.assertStops(stopsWithDepartures);
data.assertSameStopTransfers(Set.of());
data.assertBetweenStopTransfers(Set.of());

List<String> stopsWithDepartures = List.of("A", "B1", "B2", "C", "C1");
for (String stopWithDeparture : stopsWithDepartures) {
data.assertStopExists(stopWithDeparture);
if (stopWithDeparture.equals("A")) {
Expand All @@ -136,10 +136,10 @@ void noTransfers() throws NoSuchFieldException, IllegalAccessException {
}
}

// they do not have any departures, but should still exist in the raptor data
List<String> stopsWithoutDepartures = List.of("B", "C2", "D");
// they do not have any departures, and therefore should not be included in the raptor data
Set<String> stopsWithoutDepartures = Set.of("B", "C2", "D");
for (String stopWithoutDeparture : stopsWithoutDepartures) {
data.assertStopWithNoDeparturesExists(stopWithoutDeparture);
data.assertStopWithNoDeparturesNotExists(stopWithoutDeparture);
}
}

Expand All @@ -150,10 +150,10 @@ void sameStopTransfersOnAllStopsWithDepartures() throws NoSuchFieldException, Il

RaptorBuilderData data = convertRaptor(sameStopTransfers, List.of());

data.assertStops(Set.of("A", "B", "B1", "B2", "C", "C1", "C2", "D"));
data.assertSameStopTransfers(Set.of("A-120", "B1-120", "B2-120", "C-120", "C1-120", "C2-120"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
data.assertSameStopTransfers(Set.of("A-120", "B1-120", "B2-120", "C-120", "C1-120"));
// since C is also a parent stop, additional transfer C1 -> C and C -> C1 will also be generated
data.assertBetweenStopTransfers(Set.of("B-B1", "B-B2", "C-C1", "C-C2", "C1-C", "C1-C2", "C2-C", "C2-C1"));
data.assertBetweenStopTransfers(Set.of("C-C1", "C1-C"));
}

@Test
Expand All @@ -163,15 +163,11 @@ void sameStopTransfersOnParentStops() throws NoSuchFieldException, IllegalAccess

RaptorBuilderData data = convertRaptor(sameStopTransfers, List.of());

data.assertStops(Set.of("A", "B", "B1", "B2", "C", "C1", "C2", "D"));
data.assertSameStopTransfers(
Set.of("A-120", "B-120", "B1-120", "B2-120", "C-120", "C1-120", "C2-120", "D-120"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
data.assertSameStopTransfers(Set.of("A-120", "B1-120", "B2-120", "C-120", "C1-120"));

// D has no departures and not transfers specified, it should be included in the raptor data as stop,
// but should not have any between stop transfers
data.assertBetweenStopTransfers(
Set.of("B-B1", "B-B2", "B1-B", "B1-B2", "B2-B", "B2-B1", "C-C1", "C-C2", "C1-C", "C1-C2", "C2-C",
"C2-C1"));
// B is not active, but B1 and B2 are active and C and C1 are active:
data.assertBetweenStopTransfers(Set.of("B1-B2", "B2-B1", "C-C1", "C1-C"));
}

@Test
Expand All @@ -181,11 +177,11 @@ void sameStopTransfersOnParentAndChildStops() throws NoSuchFieldException, Illeg

RaptorBuilderData data = convertRaptor(sameStopTransfers, List.of());

data.assertStops(Set.of("A", "B", "B1", "B2", "C", "C1", "C2", "D"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
// since explicit child same stop transfers are defined, the transfer time between B1-B1 and B2-B2 should
// be 60, whereas create B1-B2, B2-B1 should be 120
data.assertSameStopTransfers(Set.of("B-120", "B1-60", "B2-60"));
data.assertBetweenStopTransfers(Set.of("B-B1", "B-B2", "B1-B", "B1-B2", "B2-B", "B2-B1"));
// be 60:
data.assertSameStopTransfers(Set.of("B1-60", "B2-60"));
data.assertBetweenStopTransfers(Set.of("B1-B2", "B2-B1"));
}

@Test
Expand All @@ -194,13 +190,11 @@ void betweenStopTransfersOnParentStops() throws NoSuchFieldException, IllegalAcc

RaptorBuilderData data = convertRaptor(scheduleTransfers, List.of());

data.assertStops(Set.of("A", "B", "B1", "B2", "C", "C1", "C2", "D"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
data.assertSameStopTransfers(Set.of());

// since B1, B2, C, and C1 are active following transfers should be derived from B-C:
data.assertBetweenStopTransfers(
Set.of("B-C", "B-C1", "B-C2", "B1-C", "B1-C1", "B1-C2", "B2-C", "B2-C1", "B2-C2", "C-B", "C-B1",
"C-B2", "C1-B", "C1-B1", "C1-B2", "C2-B", "C2-B1", "C2-B2"));
data.assertBetweenStopTransfers(Set.of("B1-C", "B1-C1", "B2-C", "B2-C1", "C-B1", "C-B2", "C1-B1", "C1-B2"));
}

@Test
Expand All @@ -211,10 +205,10 @@ void additionalTransfers() throws NoSuchFieldException, IllegalAccessException {

RaptorBuilderData data = convertRaptor(scheduleTransfers, additionalTransfers);

data.assertStops(Set.of("A", "B", "B1", "B2", "C", "C1", "C2", "D"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
// since additional transfers should not be applied if gtfs data exists B1-B1 should remain 120
data.assertSameStopTransfers(Set.of("B1-120", "B2-60"));
data.assertBetweenStopTransfers(Set.of("B-B1", "B1-B2"));
data.assertBetweenStopTransfers(Set.of("B1-B2"));
}

record Transfer(String fromStopId, String toStopId, int duration) {
Expand Down Expand Up @@ -303,8 +297,8 @@ void assertStopExists(String stopId) {
assertThat(stops.containsKey(stopId)).isTrue();
}

void assertStopWithNoDeparturesExists(String stopId) {
assertThat(stops.containsKey(stopId)).isTrue();
void assertStopWithNoDeparturesNotExists(String stopId) {
assertThat(stops.containsKey(stopId)).isFalse();
}

void assertStopHasNumRoutes(String stopId, int numRoutes) {
Expand Down

0 comments on commit 5d0d015

Please sign in to comment.