Skip to content

Commit

Permalink
Merge branch 'master' into 1840-invalid-characters
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamez authored Oct 21, 2024
2 parents 4de8a76 + e0f5217 commit b8ac341
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,27 @@ public class StopTimeIncreasingDistanceValidator extends FileValidator {
this.stopTimeTable = stopTimeTable;
}

@Override
public boolean shouldCallValidate() {
return stopTimeTable.hasColumn(GtfsStopTime.STOP_ID_FIELD_NAME)
&& stopTimeTable.hasColumn(GtfsStopTime.SHAPE_DIST_TRAVELED_FIELD_NAME);
}

@Override
public void validate(NoticeContainer noticeContainer) {
for (List<GtfsStopTime> stopTimeList : Multimaps.asMap(stopTimeTable.byTripIdMap()).values()) {
// GtfsStopTime objects are sorted based on @SequenceKey annotation on stop_sequence field.
for (int i = 1; i < stopTimeList.size(); ++i) {
GtfsStopTime prev = stopTimeList.get(i - 1);
GtfsStopTime curr = stopTimeList.get(i);
if (prev.hasShapeDistTraveled()
GtfsStopTime prev = null;
for (var curr : stopTimeList) {
// DecreasingOrEqualStopTimeDistanceNotice should not be triggered in cases where stop
// times has location id, location group id or stop id is not present
// See: https://github.com/MobilityData/gtfs-validator/issues/1882
if (!curr.hasStopId()) {
continue;
}

if (prev != null
&& prev.hasShapeDistTraveled()
&& curr.hasShapeDistTraveled()
&& prev.shapeDistTraveled() >= curr.shapeDistTraveled()) {
noticeContainer.addValidationNotice(
Expand All @@ -65,6 +78,7 @@ public void validate(NoticeContainer noticeContainer) {
prev.shapeDistTraveled(),
prev.stopSequence()));
}
prev = curr;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,60 @@ public void oneIntermediateShapeWithDecreasingDistanceAlongShapeShouldGenerateNo
new DecreasingOrEqualStopTimeDistanceNotice(
"first trip", "s1", 2, 8.6d, 42, 1, 10.0d, 2));
}

@Test
public void oneIntermediateShapeWithoutStopShouldBeIgnored() {
assertThat(
generateNotices(
ImmutableList.of(
createStopTime(1, "first trip", "s0", 1, 0.0d),
createStopTime(2, "first trip", "s1", 2, 45.0d),
createStopTime(3, "first trip", null, 3, 4.0d),
createStopTime(4, "first trip", "s3", 4, 64.0d))))
.isEmpty();
}

@Test
public void oneIntermediateShapeWithoutStopAndPreviousDecreasingDistanceShouldGenerateNotice() {
assertThat(
generateNotices(
ImmutableList.of(
createStopTime(1, "first trip", "s0", 1, 0.0d),
createStopTime(2, "first trip", "s1", 2, 85.0d),
createStopTime(3, "first trip", null, 3, 444.0d),
createStopTime(4, "first trip", "s3", 4, 64.0d))))
.containsExactly(
new DecreasingOrEqualStopTimeDistanceNotice(
"first trip", "s3", 4, 64.d, 4, 2, 85.0d, 2));
}

@Test
public void
multipleIntermediateShapeWithoutStopAndPreviousDecreasingDistanceShouldGenerateNotice() {
assertThat(
generateNotices(
ImmutableList.of(
createStopTime(1, "first trip", "s0", 1, 0.0d),
createStopTime(2, "first trip", "s1", 2, 85.0d),
createStopTime(3, "first trip", null, 3, 114.0d),
createStopTime(4, "first trip", null, 4, 444.0d),
createStopTime(5, "first trip", "s3", 5, 64.0d))))
.containsExactly(
new DecreasingOrEqualStopTimeDistanceNotice(
"first trip", "s3", 5, 64.d, 5, 2, 85.0d, 2));
}

@Test
public void lastShapeWithoutStopShouldBeIgnored() {
assertThat(
generateNotices(
ImmutableList.of(
createStopTime(1, "first trip", "s0", 1, 0.0d),
createStopTime(2, "first trip", "s1", 2, 2.0d),
createStopTime(3, "first trip", null, 3, 114.0d),
createStopTime(4, "first trip", null, 4, 444.0d),
createStopTime(5, "first trip", "s3", 5, 3.0d),
createStopTime(6, "first trip", null, 6, 1.0d))))
.isEmpty();
}
}

0 comments on commit b8ac341

Please sign in to comment.