forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/dev-2.x' into upstream-merge-2…
…025-02-06
- Loading branch information
Showing
88 changed files
with
1,594 additions
and
639 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...ication/src/ext-test/java/org/opentripplanner/ext/flex/FlexibleTransitLegBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.opentripplanner.ext.flex; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.opentripplanner.ext.fares.impl.FareModelForTest.FARE_PRODUCT_USE; | ||
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDate; | ||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
import java.util.Set; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner.ext.flex.edgetype.FlexTripEdge; | ||
import org.opentripplanner.ext.flex.flexpathcalculator.FlexPath; | ||
import org.opentripplanner.framework.geometry.GeometryUtils; | ||
import org.opentripplanner.framework.i18n.I18NString; | ||
import org.opentripplanner.model.plan.PlanTestConstants; | ||
import org.opentripplanner.routing.alertpatch.TransitAlert; | ||
import org.opentripplanner.street.model._data.StreetModelForTest; | ||
|
||
class FlexibleTransitLegBuilderTest implements PlanTestConstants { | ||
|
||
private static final FlexTripEdge EDGE = new FlexTripEdge( | ||
StreetModelForTest.intersectionVertex(1, 1), | ||
StreetModelForTest.intersectionVertex(2, 2), | ||
A.stop, | ||
B.stop, | ||
null, | ||
1, | ||
2, | ||
LocalDate.of(2025, 1, 15), | ||
new FlexPath(1000, 600, () -> GeometryUtils.makeLineString(1, 1, 2, 2)) | ||
); | ||
private static final TransitAlert ALERT = TransitAlert | ||
.of(id("alert")) | ||
.withHeaderText(I18NString.of("alert 1")) | ||
.build(); | ||
private static final Duration TIME_SHIFT = Duration.ofHours(5); | ||
private static final ZonedDateTime START_TIME = ZonedDateTime.parse("2025-01-14T14:01:21+01:00"); | ||
private static final ZonedDateTime END_TIME = START_TIME.plusHours(3); | ||
|
||
@Test | ||
void listsAreInitialized() { | ||
var leg = new FlexibleTransitLegBuilder() | ||
.withStartTime(START_TIME) | ||
.withEndTime(END_TIME) | ||
.withFlexTripEdge(EDGE) | ||
.build(); | ||
assertNotNull(leg.fareProducts()); | ||
assertNotNull(leg.getTransitAlerts()); | ||
} | ||
|
||
@Test | ||
void everythingIsNonNull() { | ||
var expectedType = RuntimeException.class; | ||
assertThrows(expectedType, () -> new FlexibleTransitLegBuilder().withStartTime(null).build()); | ||
assertThrows(expectedType, () -> new FlexibleTransitLegBuilder().withEndTime(null).build()); | ||
assertThrows( | ||
expectedType, | ||
() -> new FlexibleTransitLegBuilder().withFlexTripEdge(null).build() | ||
); | ||
assertThrows(expectedType, () -> new FlexibleTransitLegBuilder().withAlerts(null).build()); | ||
assertThrows( | ||
expectedType, | ||
() -> new FlexibleTransitLegBuilder().withFareProducts(null).build() | ||
); | ||
} | ||
|
||
@Test | ||
void copy() { | ||
var leg = new FlexibleTransitLegBuilder() | ||
.withStartTime(START_TIME) | ||
.withEndTime(END_TIME) | ||
.withFlexTripEdge(EDGE) | ||
.withFareProducts(List.of(FARE_PRODUCT_USE)) | ||
.withAlerts(Set.of(ALERT)) | ||
.build(); | ||
|
||
var copy = leg.copy().build(); | ||
|
||
assertEquals(copy.flexTripEdge(), EDGE); | ||
assertEquals(copy.getStartTime(), START_TIME); | ||
assertEquals(copy.getEndTime(), END_TIME); | ||
assertEquals(copy.getTransitAlerts(), Set.of(ALERT)); | ||
assertEquals(copy.fareProducts(), List.of(FARE_PRODUCT_USE)); | ||
} | ||
|
||
@Test | ||
void timeShift() { | ||
var leg = new FlexibleTransitLegBuilder() | ||
.withStartTime(START_TIME) | ||
.withEndTime(END_TIME) | ||
.withFlexTripEdge(EDGE) | ||
.withFareProducts(List.of(FARE_PRODUCT_USE)) | ||
.withAlerts(Set.of(ALERT)) | ||
.build(); | ||
|
||
var shifted = leg.withTimeShift(TIME_SHIFT); | ||
|
||
assertEquals(START_TIME.plus(TIME_SHIFT), shifted.getStartTime()); | ||
assertEquals(END_TIME.plus(TIME_SHIFT), shifted.getEndTime()); | ||
assertEquals(List.of(FARE_PRODUCT_USE), shifted.fareProducts()); | ||
assertEquals(Set.of(ALERT), shifted.getTransitAlerts()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
.../java/org/opentripplanner/ext/stopconsolidation/model/ConsolidatedStopLegBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package org.opentripplanner.ext.stopconsolidation.model; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.opentripplanner.ext.fares.impl.FareModelForTest.FARE_PRODUCT_USE; | ||
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Set; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner._support.time.ZoneIds; | ||
import org.opentripplanner.framework.i18n.I18NString; | ||
import org.opentripplanner.model.fare.FareProductUse; | ||
import org.opentripplanner.model.plan.PlanTestConstants; | ||
import org.opentripplanner.model.plan.ScheduledTransitLeg; | ||
import org.opentripplanner.model.plan.ScheduledTransitLegBuilder; | ||
import org.opentripplanner.routing.alertpatch.TransitAlert; | ||
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest; | ||
import org.opentripplanner.transit.model.basic.TransitMode; | ||
import org.opentripplanner.transit.model.network.TripPattern; | ||
|
||
class ConsolidatedStopLegBuilderTest implements PlanTestConstants { | ||
|
||
private static final Set<TransitAlert> ALERTS = Set.of( | ||
TransitAlert.of(id("alert")).withDescriptionText(I18NString.of("alert")).build() | ||
); | ||
private static final TripPattern PATTERN = TimetableRepositoryForTest | ||
.of() | ||
.pattern(TransitMode.BUS) | ||
.build(); | ||
private static final ScheduledTransitLeg SCHEDULED_TRANSIT_LEG = new ScheduledTransitLegBuilder<>() | ||
.withZoneId(ZoneIds.BERLIN) | ||
.withServiceDate(LocalDate.of(2025, 1, 15)) | ||
.withTripPattern(PATTERN) | ||
.withBoardStopIndexInPattern(0) | ||
.withDistanceMeters(1000) | ||
.withAlightStopIndexInPattern(1) | ||
.build(); | ||
private static final List<FareProductUse> FARES = List.of(FARE_PRODUCT_USE); | ||
|
||
@Test | ||
void build() { | ||
var leg = new ConsolidatedStopLegBuilder(SCHEDULED_TRANSIT_LEG) | ||
.withFrom(E.stop) | ||
.withTo(F.stop) | ||
.build(); | ||
assertEquals(E.stop, leg.getFrom().stop); | ||
assertEquals(F.stop, leg.getTo().stop); | ||
} | ||
|
||
@Test | ||
void copyAttributesFromConsolidatedStopLeg() { | ||
var leg = new ConsolidatedStopLegBuilder(SCHEDULED_TRANSIT_LEG) | ||
.withFrom(E.stop) | ||
.withTo(F.stop) | ||
.build(); | ||
|
||
var copy = leg | ||
.copy() | ||
.withAccessibilityScore(4f) | ||
.withFareProducts(FARES) | ||
.withAlerts(Set.of(ALERTS)) | ||
.build(); | ||
|
||
assertEquals(leg.getFrom().stop, copy.getFrom().stop); | ||
assertEquals(leg.getTo().stop, copy.getTo().stop); | ||
assertEquals(Set.of(ALERTS), copy.getTransitAlerts()); | ||
assertEquals(FARES, copy.fareProducts()); | ||
assertEquals(ZoneIds.BERLIN, copy.getZoneId()); | ||
} | ||
|
||
@Test | ||
void copyConsolidatedLeg() { | ||
var leg = new ConsolidatedStopLegBuilder(SCHEDULED_TRANSIT_LEG) | ||
.withFrom(E.stop) | ||
.withTo(F.stop) | ||
.withAlerts(ALERTS) | ||
.build(); | ||
|
||
var copy = leg.copy().build(); | ||
|
||
assertEquals(E.stop, copy.getFrom().stop); | ||
assertEquals(F.stop, copy.getTo().stop); | ||
assertEquals(ALERTS, copy.getTransitAlerts()); | ||
} | ||
|
||
@Test | ||
void copyAttributesFromScheduledLeg() { | ||
var leg = SCHEDULED_TRANSIT_LEG | ||
.copy() | ||
.withFareProducts(FARES) | ||
.withAlerts(Set.of(ALERTS)) | ||
.build(); | ||
|
||
var copy = new ConsolidatedStopLegBuilder(leg).withFrom(C.stop).withTo(G.stop).build(); | ||
|
||
assertEquals(C.stop, copy.getFrom().stop); | ||
assertEquals(G.stop, copy.getTo().stop); | ||
assertEquals(Set.of(ALERTS), copy.getTransitAlerts()); | ||
assertEquals(FARES, copy.fareProducts()); | ||
assertEquals(ZoneIds.BERLIN, copy.getZoneId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.