Skip to content

Commit

Permalink
Add place finder tests for rental
Browse files Browse the repository at this point in the history
  • Loading branch information
optionsome committed Jul 4, 2024
1 parent b64b08a commit 9a3edc1
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PlaceFinderTraverseVisitor implements TraverseVisitor<State, Edge>
private final Set<FeedScopedId> filterByStops;
private final Set<FeedScopedId> filterByStations;
private final Set<FeedScopedId> filterByRoutes;
private final Set<String> filterByNetwork;
private final Set<String> filterByVehicleRental;
private final Set<String> seenPatternAtStops = new HashSet<>();
private final Set<FeedScopedId> seenStops = new HashSet<>();
Expand All @@ -44,7 +45,6 @@ public class PlaceFinderTraverseVisitor implements TraverseVisitor<State, Edge>
private final boolean includeStations;
private final int maxResults;
private final double radiusMeters;
private final Set<String> filterByNetwork;

/**
* @param transitService A TransitService used in finding information about the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.model.StopTime;
import org.opentripplanner.service.vehiclerental.model.TestVehicleRentalStationBuilder;
import org.opentripplanner.street.search.state.TestStateBuilder;
import org.opentripplanner.transit.model._data.TransitModelForTest;
import org.opentripplanner.transit.model.basic.TransitMode;
Expand Down Expand Up @@ -280,4 +281,74 @@ void stopsAndStationsWithStopAndStationFilter() {

visitor.visitVertex(state1);
}

@Test
void rentalStation() {
var visitor = new PlaceFinderTraverseVisitor(
transitService,
null,
List.of(PlaceType.VEHICLE_RENT),
null,
null,
null,
null,
null,
1,
500
);
var station = new TestVehicleRentalStationBuilder().build();
assertEquals(List.of(), visitor.placesFound);
var state1 = TestStateBuilder.ofWalking().rentalStation(station).build();
visitor.visitVertex(state1);

var res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList();

assertEquals(List.of(station), res);
}

@Test
void rentalStationWithNetworksFilter() {
var visitor = new PlaceFinderTraverseVisitor(
transitService,
null,
List.of(PlaceType.VEHICLE_RENT),
null,
null,
null,
null,
List.of("Network-1"),
1,
500
);
var station = new TestVehicleRentalStationBuilder().build();
assertEquals(List.of(), visitor.placesFound);
var state1 = TestStateBuilder.ofWalking().rentalStation(station).build();
visitor.visitVertex(state1);

var res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList();

assertEquals(List.of(station), res);

visitor =
new PlaceFinderTraverseVisitor(
transitService,
null,
List.of(PlaceType.VEHICLE_RENT),
null,
null,
null,
null,
List.of("Network-2"),
1,
500
);

assertEquals(List.of(), visitor.placesFound);
state1 = TestStateBuilder.ofWalking().rentalStation(station).build();
visitor.visitVertex(state1);

res = visitor.placesFound.stream().map(PlaceAtDistance::place).toList();

assertEquals(List.of(), res);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.opentripplanner.service.vehiclerental.model.TestFreeFloatingRentalVehicleBuilder;
import org.opentripplanner.service.vehiclerental.model.TestVehicleRentalStationBuilder;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation;
import org.opentripplanner.service.vehiclerental.street.StreetVehicleRentalLink;
import org.opentripplanner.service.vehiclerental.street.VehicleRentalEdge;
import org.opentripplanner.service.vehiclerental.street.VehicleRentalPlaceVertex;
Expand Down Expand Up @@ -219,6 +220,19 @@ public TestStateBuilder stop() {
return arriveAtStop(testModel.stop("stop", count, count).build());
}

/**
* Add a state that arrives at a rental station.
*/
public TestStateBuilder rentalStation(VehicleRentalStation station) {
count++;
var from = (StreetVertex) currentState.vertex;
var to = new VehicleRentalPlaceVertex(station);

var link = StreetVehicleRentalLink.createStreetVehicleRentalLink(from, to);
currentState = link.traverse(currentState)[0];
return this;
}

public TestStateBuilder enterStation(String id) {
count++;
var from = (StreetVertex) currentState.vertex;
Expand Down

0 comments on commit 9a3edc1

Please sign in to comment.