Skip to content

Commit

Permalink
Flesh out tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Sep 17, 2024
1 parent bf35839 commit 0e31b24
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/opentripplanner/model/plan/Itinerary.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ public boolean hasTransit() {
.anyMatch(l -> l instanceof ScheduledTransitLeg || l instanceof FlexibleTransitLeg);
}

/**
* Returns true if this itinerary was produced by an algorithm that is aware of the search window.
* As of 2024 only the itineraries produced by RAPTOR that do that.
*/
public boolean isSearchWindowAware() {
return isSearchWindowAware;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.opentripplanner.routing.algorithm.mapping;

import static org.junit.jupiter.api.Assertions.assertFalse;

import org.junit.jupiter.api.Test;
import org.opentripplanner._support.time.ZoneIds;
import org.opentripplanner.astar.model.GraphPath;
import org.opentripplanner.routing.services.notes.StreetNotesService;
import org.opentripplanner.street.search.state.TestStateBuilder;

class GraphPathToItineraryMapperTest {

@Test
void isSearchWindowAware() {
var mapper = new GraphPathToItineraryMapper(ZoneIds.UTC, new StreetNotesService(), 1);
var state = TestStateBuilder.ofWalking().streetEdge().streetEdge().streetEdge().build();
var itin = mapper.generateItinerary(new GraphPath<>(state));
assertFalse(itin.isSearchWindowAware());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opentripplanner.raptor._data.RaptorTestConstants.BOARD_SLACK;

import java.time.Duration;
Expand Down Expand Up @@ -184,6 +185,16 @@ void createItineraryWithOnBoardFlexAccess() {
assertEquals(3, itinerary.getLegs().size(), "The wrong number of legs was returned");
}

@Test
void isSearchWindowAware() {
var mapper = getRaptorPathToItineraryMapper();

var path = createTestTripSchedulePath(getTestTripSchedule())
.egress(TestAccessEgress.free(2, RaptorCostConverter.toRaptorCost(100)));
var itinerary = mapper.createItinerary(path);
assertTrue(itinerary.isSearchWindowAware());
}

private TripPattern getOriginalPattern(TestTripPattern pattern) {
var stopModelBuilder = TEST_MODEL.stopModelBuilder();
ArrayList<StopTime> stopTimes = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ void testPreviousLegs() {
assertEquals(expected, legs);
}

private static String getStr(List<ScheduledTransitLeg> alternativeLegs) {
return Itinerary.toStr(
alternativeLegs
.stream()
.map(Leg.class::cast)
.map(List::of)
.map(l -> new Itinerary(l, true))
.toList()
);
}

@Test
void testNextLegs() {
var transitService = new DefaultTransitService(transitModel);
Expand Down Expand Up @@ -166,4 +155,15 @@ void testComplexCircularRoutes() {
var expected = String.join(", ", List.of("X ~ BUS 19 10:30 11:00 ~ B [C₁-1]"));
assertEquals(expected, legs);
}

private static String getStr(List<ScheduledTransitLeg> alternativeLegs) {
return Itinerary.toStr(
alternativeLegs
.stream()
.map(Leg.class::cast)
.map(List::of)
.map(l -> new Itinerary(l, true))
.toList()
);
}
}

0 comments on commit 0e31b24

Please sign in to comment.