Skip to content

Commit

Permalink
Re-implement test by checking the calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed May 23, 2024
1 parent 57c4282 commit 3faf591
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.opentripplanner.ext.flex;
package org.opentripplanner.ext.flex.trip;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.opentripplanner.graph_builder.issue.api.DataImportIssueStore.NOOP;

import java.util.List;
import org.junit.jupiter.api.Test;
import org.opentripplanner.ext.flex.FlexStopTimesForTest;
import org.opentripplanner.ext.flex.FlexTripsMapper;
import org.opentripplanner.ext.flex.flexpathcalculator.DirectFlexPathCalculator;
import org.opentripplanner.model.StopTime;
import org.opentripplanner.model.impl.OtpTransitServiceBuilder;
import org.opentripplanner.transit.model._data.TransitModelForTest;
Expand All @@ -18,7 +22,10 @@ void defaultTimePenalty() {
var stopTimes = List.of(stopTime(0), stopTime(1));
builder.getStopTimesSortedByTrip().addAll(stopTimes);
var trips = FlexTripsMapper.createFlexTrips(builder, NOOP);
assertEquals("[UnscheduledTrip{F:flex-1 timePenalty=(0s + 1.00 t)}]", trips.toString());
assertEquals("[UnscheduledTrip{F:flex-1}]", trips.toString());
var unscheduled = (UnscheduledTrip) trips.getFirst();
var unchanged = unscheduled.flexPathCalculator(new DirectFlexPathCalculator());
assertInstanceOf(DirectFlexPathCalculator.class, unchanged);
}

private static StopTime stopTime(int seq) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opentripplanner.ext.flex.FlexServiceDate;
import org.opentripplanner.ext.flex.flexpathcalculator.FlexPathCalculator;
import org.opentripplanner.ext.flex.flexpathcalculator.TimePenaltyCalculator;
Expand All @@ -30,7 +29,6 @@
import org.opentripplanner.routing.graphfinder.NearbyStop;
import org.opentripplanner.standalone.config.sandbox.FlexConfig;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.framework.LogInfo;
import org.opentripplanner.transit.model.framework.TransitBuilder;
import org.opentripplanner.transit.model.site.GroupStop;
import org.opentripplanner.transit.model.site.StopLocation;
Expand All @@ -47,9 +45,7 @@
* <p>
* For a discussion of this behaviour see https://github.com/MobilityData/gtfs-flex/issues/76
*/
public class UnscheduledTrip
extends FlexTrip<UnscheduledTrip, UnscheduledTripBuilder>
implements LogInfo {
public class UnscheduledTrip extends FlexTrip<UnscheduledTrip, UnscheduledTripBuilder> {

private static final Set<Integer> N_STOPS = Set.of(1, 2);
private static final int INDEX_NOT_FOUND = -1;
Expand Down Expand Up @@ -158,12 +154,6 @@ public Stream<FlexAccessTemplate> getFlexAccessTemplates(
);
}

@Nullable
@Override
public String logName() {
return "timePenalty=(%s)".formatted(timePenalty.toString());
}

/**
* Get the correct {@link FlexPathCalculator} depending on the {@code timePenalty}.
* If the penalty would not change the result, we return the regular calculator.
Expand Down

0 comments on commit 3faf591

Please sign in to comment.