Skip to content

Commit

Permalink
Also combine with multiple locations to increase number of tests quit…
Browse files Browse the repository at this point in the history
…e dramatically
  • Loading branch information
leonardehrenfried committed Nov 22, 2023
1 parent 1e75a5c commit 78d9736
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -81,7 +83,7 @@ public void flexRouteFromCentralAtlantaToPowderSprings() {

static List<TripPlanParameters> buildCombinations() {
return new RequestCombinationsBuilder()
.withLocations(lindberghCenter, peachtreeCreek)
.withLocations(lindberghCenter, peachtreeCreek, maddoxPark, druidHills)
.withModes(TRANSIT, WALK)
.withTime(SmokeTest.weekdayAtNoon())
.includeWheelchair()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Coordinate> places;
private LocalDateTime time;
private Set<RequestMode> 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;
}

Expand All @@ -53,11 +53,9 @@ public RequestCombinationsBuilder withModes(RequestMode... requestMode) {
}

public List<TripPlanParameters> build() {
var builder1 = new TripPlanParametersBuilder().withFrom(p1).withTo(p2);
var builder2 = new TripPlanParametersBuilder().withFrom(p2).withTo(p1);
Stream<TripPlanParametersBuilder> 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 ->
Expand All @@ -79,4 +77,13 @@ private Stream<TripPlanParametersBuilder> duplicateIf(
return Stream.of(original);
}
}

private static Stream<TripPlanParametersBuilder> combineLocations(List<Coordinate> 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));
});
}
}

0 comments on commit 78d9736

Please sign in to comment.