Skip to content

Commit

Permalink
add test for opentripplanner#6391
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Jan 17, 2025
1 parent 4c3983b commit f60c1db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ public TripUpdateBuilder addDelayedStopTime(int stopSequence, int delay) {
return addStopTime(null, -1, stopSequence, delay, delay, DEFAULT_SCHEDULE_RELATIONSHIP, null);
}

public TripUpdateBuilder addDelayedArrivalStopTime(int stopSequence, int arrivalDelay) {
return addStopTime(
null,
-1,
stopSequence,
arrivalDelay,
NO_DELAY,
DEFAULT_SCHEDULE_RELATIONSHIP,
null
);
}

public TripUpdateBuilder addDelayedStopTime(
int stopSequence,
int arrivalDelay,
Expand Down Expand Up @@ -166,6 +178,14 @@ private TripUpdateBuilder addStopTime(
departureBuilder.setDelay(departureDelay);
}

if (!arrivalBuilder.hasTime() && !arrivalBuilder.hasDelay()) {
stopTimeUpdateBuilder.clearArrival();
}

if (!departureBuilder.hasTime() && !departureBuilder.hasDelay()) {
stopTimeUpdateBuilder.clearDeparture();
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ void singleStopDelay() {
void complexDelay() {
var tripInput = TripInput
.of(TRIP_2_ID)
.addStop(STOP_A1, "0:01:00", "0:01:01")
.addStop(STOP_B1, "0:01:10", "0:01:11")
.addStop(STOP_C1, "0:01:20", "0:01:21")
.addStop(STOP_A1, "0:00:00", "0:00:00")
.addStop(STOP_B1, "0:05:00", "0:10:00") // 5-minute dwell
.addStop(STOP_C1, "0:15:00", "0:16:00")
.build();
var env = RealtimeTestEnvironment.gtfs().addTrip(tripInput).build();

var tripUpdate = new TripUpdateBuilder(TRIP_2_ID, SERVICE_DATE, SCHEDULED, TIME_ZONE)
.addDelayedStopTime(0, 0)
.addDelayedStopTime(1, 60, 80)
.addDelayedStopTime(2, 90, 90)
.addDelayedArrivalStopTime(1, 900) // arrival delayed until 00:20
.addDelayedStopTime(2, 540) // delayed until 00:24 arr / 00:25 dep
.build();

assertSuccess(env.applyTripUpdate(tripUpdate));
Expand Down Expand Up @@ -119,11 +119,11 @@ void complexDelay() {
);

assertEquals(
"SCHEDULED | A1 0:01 0:01:01 | B1 0:01:10 0:01:11 | C1 0:01:20 0:01:21",
"SCHEDULED | A1 0:00 0:00 | B1 0:05 0:10 | C1 0:15 0:15",
env.getScheduledTimetable(TRIP_2_ID)
);
assertEquals(
"UPDATED | A1 0:01 0:01:01 | B1 0:02:10 0:02:31 | C1 0:02:50 0:02:51",
"UPDATED | A1 0:00 0:00 | B1 0:20 0:20 | C1 0:24 0:25",
env.getRealtimeTimetable(TRIP_2_ID)
);
}
Expand Down

0 comments on commit f60c1db

Please sign in to comment.