From 78d9736e04f711df2dd0e5681e667dbbf3ba78b8 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Wed, 22 Nov 2023 15:17:58 +0100 Subject: [PATCH] Also combine with multiple locations to increase number of tests quite dramatically --- .../smoketest/AtlantaSmokeTest.java | 4 ++- .../util/RequestCombinationsBuilder.java | 29 ++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/opentripplanner/smoketest/AtlantaSmokeTest.java b/src/test/java/org/opentripplanner/smoketest/AtlantaSmokeTest.java index e0bbdd3e8b6..b9c529289ec 100644 --- a/src/test/java/org/opentripplanner/smoketest/AtlantaSmokeTest.java +++ b/src/test/java/org/opentripplanner/smoketest/AtlantaSmokeTest.java @@ -42,6 +42,8 @@ public class AtlantaSmokeTest { static Coordinate peachtreeCreek = new Coordinate(33.7310, -84.3823); static Coordinate lindberghCenter = new Coordinate(33.8235, -84.3674); + static Coordinate maddoxPark = new Coordinate(33.7705, -84.4265); + static Coordinate druidHills = new Coordinate(33.77933, -84.33689); @Test public void regularRouteFromCentralAtlantaToPowderSprings() { @@ -81,7 +83,7 @@ public void flexRouteFromCentralAtlantaToPowderSprings() { static List buildCombinations() { return new RequestCombinationsBuilder() - .withLocations(lindberghCenter, peachtreeCreek) + .withLocations(lindberghCenter, peachtreeCreek, maddoxPark, druidHills) .withModes(TRANSIT, WALK) .withTime(SmokeTest.weekdayAtNoon()) .includeWheelchair() diff --git a/src/test/java/org/opentripplanner/smoketest/util/RequestCombinationsBuilder.java b/src/test/java/org/opentripplanner/smoketest/util/RequestCombinationsBuilder.java index bc83e70645d..ce2bdacb334 100644 --- a/src/test/java/org/opentripplanner/smoketest/util/RequestCombinationsBuilder.java +++ b/src/test/java/org/opentripplanner/smoketest/util/RequestCombinationsBuilder.java @@ -3,6 +3,7 @@ import static org.opentripplanner.client.parameters.TripPlanParameters.SearchDirection.ARRIVE_BY; import java.time.LocalDateTime; +import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -11,24 +12,23 @@ import org.opentripplanner.client.model.RequestMode; import org.opentripplanner.client.parameters.TripPlanParameters; import org.opentripplanner.client.parameters.TripPlanParametersBuilder; +import org.opentripplanner.framework.collection.ListUtils; /** * Generates all possible combinations of requests given input parameters. - * For the coordinates will be used for start and end, wheelchair will be on/off and the search - * direction (depart at/arrive by) toggled. + * For example the coordinates will be used for start and end, wheelchair will be on/off and the + * search direction (depart at/arrive by) toggled. */ public class RequestCombinationsBuilder { - private Coordinate p1; - private Coordinate p2; + private List places; private LocalDateTime time; private Set modes; private boolean includeWheelchair = false; private boolean includeArriveBy = false; - public RequestCombinationsBuilder withLocations(Coordinate p1, Coordinate p2) { - this.p1 = p1; - this.p2 = p2; + public RequestCombinationsBuilder withLocations(Coordinate p1, Coordinate p2, Coordinate... p3) { + this.places = ListUtils.combine(List.of(p1, p2), Arrays.asList(p3)); return this; } @@ -53,11 +53,9 @@ public RequestCombinationsBuilder withModes(RequestMode... requestMode) { } public List build() { - var builder1 = new TripPlanParametersBuilder().withFrom(p1).withTo(p2); - var builder2 = new TripPlanParametersBuilder().withFrom(p2).withTo(p1); + Stream builder = combineLocations(places); - return Stream - .of(builder1, builder2) + return builder .map(b -> b.withTime(time).withModes(modes)) .flatMap(original -> duplicateIf(includeWheelchair, original, o -> o.withWheelchair(true))) .flatMap(original -> @@ -79,4 +77,13 @@ private Stream duplicateIf( return Stream.of(original); } } + + private static Stream combineLocations(List places) { + return places + .stream() + .flatMap(place -> { + var builder = TripPlanParameters.builder().withFrom(place); + return places.stream().filter(p -> !p.equals(place)).map(p -> builder.copy().withTo(p)); + }); + } }