Skip to content

Commit

Permalink
TEST: #181 - Extend test gtfs schedule for raptorgtfs service tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
clukas1 committed Feb 15, 2025
1 parent 1615e6e commit 3784c80
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
/**
* GTFS schedule builder for testing. Builds a schedule as below
* <pre>
* |--------B1------------C1
* |--------B1------------C1-----------D1
* |
* A---| (B) |-----C (D)
* | |
* |--------B2 -----| (C2)
* A---| (B) |-----C-------| (D) (E)
* | | |
* |--------B2 -----| (C2) |----D2
* </pre>
* <ul>
* <li><b>Route 1</b>: Passes through A - B1 - C1</li>
* <li><b>Route 2</b>: Passes through A - B2 - C</li>
* <li><b>Route 1</b>: Passes through A - B1 - C1 - D1</li>
* <li><b>Route 2</b>: Passes through A - B2 - C - D2</li>
* </ul>
* 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.
* Stops B, C2, D, E have no departures/arrivals and should not be included in the raptor conversion.
* Stops B, C, D are parents of stops (B1, B2), (C1, C2) and (D1, D2) respectively.
*/
public class GtfsRaptorTestSchedule {

Expand All @@ -47,20 +47,25 @@ private void setup() {
builder.addStop("C1", "C1", 0.001, 2.0, "C", AccessibilityInformation.UNKNOWN);
builder.addStop("C2", "C2", -0.001, 2.0, "C", AccessibilityInformation.UNKNOWN);
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("E", "E", 0.0, 4.0);

// Route 1 goes from A, B1, C1
// Route 1 goes from A, B1, C1, D2
builder.addRoute("R1", "agency", "R1", "R1", RouteType.parse(1));
builder.addTrip("T1", "R1", "always", "C1");
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.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));
builder.addStopTime("T2", "D2", new ServiceDayTime(420), new ServiceDayTime(480));
}

public void addTransfer(String fromStopId, String toStopId, TransferType type, int duration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,21 @@ void shouldConvertGtfsScheduleToRaptor() {

@Nested
class ManualSchedule {

/**
* All tests run with a fixed set of stops and routes in a GTFS schedule as shown below:
* <pre>
* |--------B1------------C1
* |--------B1------------C1-----------D1
* |
* A---| (B) |-----C (D)
* | |
* |--------B2 -----| (C2)
* A---| (B) |-----C-------| (D) (E)
* | | |
* |--------B2 -----| (C2) |----D2
* </pre>
* <ul>
* <li><b>Route 1</b>: Passes through A - B1 - C1</li>
* <li><b>Route 2</b>: Passes through A - B2 - C</li>
* <li><b>Route 1</b>: Passes through A - B1 - C1 - D1</li>
* <li><b>Route 2</b>: Passes through A - B2 - C - D2</li>
* </ul>
* 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.
* Stops B, C2, D, E have no departures/arrivals and should not be included in the raptor conversion.
* Stops B, C, D are parents of stops (B1, B2), (C1, C2) and (D1, D2) respectively.
*/
static RaptorBuilderData convertRaptor(List<Transfer> scheduleTransfers,
List<TransferGenerator> transferGenerators) throws NoSuchFieldException, IllegalAccessException {
Expand All @@ -84,7 +83,7 @@ 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");
Set<String> stopsWithDepartures = Set.of("A", "B1", "B2", "C", "C1", "D1", "D2");

data.assertStops(stopsWithDepartures);
data.assertSameStopTransfers(Set.of());
Expand Down Expand Up @@ -113,7 +112,7 @@ void sameStopTransfersOnAllStopsWithDepartures() throws NoSuchFieldException, Il

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

data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1", "D1", "D2"));
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("C-C1", "C1-C"));
Expand All @@ -122,15 +121,15 @@ void sameStopTransfersOnAllStopsWithDepartures() throws NoSuchFieldException, Il
@Test
void sameStopTransfersOnParentStops() throws NoSuchFieldException, IllegalAccessException {
List<Transfer> sameStopTransfers = List.of(new Transfer("A", "A", 120), new Transfer("B", "B", 120),
new Transfer("C", "C", 120), new Transfer("D", "D", 120));
new Transfer("C", "C", 120), new Transfer("D", "D", 120), new Transfer("E", "D", 120));

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

data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
data.assertSameStopTransfers(Set.of("A-120", "B1-120", "B2-120", "C-120", "C1-120"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1", "D1", "D2"));
data.assertSameStopTransfers(Set.of("A-120", "B1-120", "B2-120", "C-120", "C1-120", "D1-120", "D2-120"));

// 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"));
// B, D and E are not active, but B1 and B2, C and C1 and D1 and D2 are active:
data.assertBetweenStopTransfers(Set.of("B1-B2", "B2-B1", "C-C1", "C1-C", "D1-D2", "D2-D1"));
}

@Test
Expand All @@ -140,7 +139,7 @@ void sameStopTransfersOnParentAndChildStops() throws NoSuchFieldException, Illeg

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

data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1", "D1", "D2"));
// since explicit child same stop transfers are defined, the transfer time between B1-B1 and B2-B2 should
// be 60:
data.assertSameStopTransfers(Set.of("B1-60", "B2-60"));
Expand All @@ -153,7 +152,7 @@ void betweenStopTransfersOnParentStops() throws NoSuchFieldException, IllegalAcc

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

data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1", "D1", "D2"));
data.assertSameStopTransfers(Set.of());

// since B1, B2, C, and C1 are active following transfers should be derived from B-C:
Expand All @@ -171,7 +170,7 @@ void additionalTransfers() throws NoSuchFieldException, IllegalAccessException {

RaptorBuilderData data = convertRaptor(scheduleTransfers, transferGenerators);

data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1", "D1", "D2"));
// since LL 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("B1-B2"));
Expand All @@ -190,7 +189,7 @@ void multipleTransferGenerators() throws NoSuchFieldException, IllegalAccessExce
List<TransferGenerator> transferGenerators = List.of(transferGenerator1, transferGenerator2);

RaptorBuilderData data = convertRaptor(scheduleTransfers, transferGenerators);
data.assertStops(Set.of("A", "B1", "B2", "C", "C1"));
data.assertStops(Set.of("A", "B1", "B2", "C", "C1", "D1", "D2"));
// because schedule transfers have the highest priority B1-B1 should be 120
// in case of multiple transfer generators the first should have the highest and the last should have the
// lowest priority, therefore B2-B2 should be 90 (defined in both) and C1-C1 should be 60 (only defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class NoWalkableAlternative {
@BeforeEach
void setUp() {
source = getStopById("A");
target = getStopById("D");
target = getStopById("E");
}

@Test
Expand Down Expand Up @@ -407,7 +407,7 @@ void departure() throws ConnectionRoutingException {
Map<Stop, ch.naviqore.service.Connection> isolines = facade.queryIsolines(DATE_TIME, TimeType.DEPARTURE,
QUERY_CONFIG, sourceStop);

assertThat(isolines).hasSize(4);
assertThat(isolines).hasSize(6);

for (Connection isoline : isolines.values()) {
assertThat(isoline.getLegs()).hasSize(1);
Expand Down Expand Up @@ -442,7 +442,7 @@ void departure() throws ConnectionRoutingException {
Map<Stop, ch.naviqore.service.Connection> isolines = facade.queryIsolines(DATE_TIME, TimeType.DEPARTURE,
QUERY_CONFIG, sourceCoordinate);

assertThat(isolines).hasSize(4);
assertThat(isolines).hasSize(6);

for (Connection isoline : isolines.values()) {
assertThat(isoline.getLegs()).hasSize(2);
Expand Down Expand Up @@ -497,7 +497,7 @@ void departure() throws ConnectionRoutingException {
@Test
void arrival() throws ConnectionRoutingException {
Map<Stop, ch.naviqore.service.Connection> isolines = facade.queryIsolines(DATE_TIME,
TimeType.ARRIVAL, QUERY_CONFIG, getStopById("D"));
TimeType.ARRIVAL, QUERY_CONFIG, getStopById("E"));

assertThat(isolines).isEmpty();
}
Expand All @@ -510,9 +510,9 @@ class WalkableAlternative {
@Test
void departure() throws ConnectionRoutingException {
Map<Stop, ch.naviqore.service.Connection> isolines = facade.queryIsolines(DATE_TIME,
TimeType.DEPARTURE, QUERY_CONFIG, getStopById("C2"));
TimeType.DEPARTURE, QUERY_CONFIG, getStopById("D"));

// Expected behavior: Since no departures from stops C, C1 and C2, the result must be empty.
// Expected behavior: Since no departures from stops D, D1 and D2, the result must be empty.
assertThat(isolines).isEmpty();
}

Expand Down

0 comments on commit 3784c80

Please sign in to comment.