Skip to content

Commit

Permalink
Only compute the accessibility score for walking legs
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Sep 1, 2024
1 parent d2f4b2d commit 4b47ea2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary;

import java.util.List;
import java.util.function.Function;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.FieldSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.PlanTestConstants;
import org.opentripplanner.model.plan.TestItineraryBuilder;
import org.opentripplanner.routing.api.request.preference.WheelchairPreferences;

public class DecorateWithAccessibilityScoreTest implements PlanTestConstants {
class DecorateWithAccessibilityScoreTest implements PlanTestConstants {

private static final int ID = 1;
private static final DecorateWithAccessibilityScore DECORATOR = new DecorateWithAccessibilityScore(
WheelchairPreferences.DEFAULT.maxSlope()
);

static List<Arguments> accessibilityScoreTestCase() {
return List.of(
Expand Down Expand Up @@ -48,17 +55,26 @@ static List<Arguments> accessibilityScoreTestCase() {

@ParameterizedTest
@MethodSource("accessibilityScoreTestCase")
public void accessibilityScoreTest(Itinerary itinerary, float expectedAccessibilityScore) {
var filter = new DecorateWithAccessibilityScore(WheelchairPreferences.DEFAULT.maxSlope());

filter.decorate(itinerary);
void accessibilityScoreTest(Itinerary itinerary, float expectedAccessibilityScore) {
DECORATOR.decorate(itinerary);

assertEquals(expectedAccessibilityScore, itinerary.getAccessibilityScore());

itinerary
.getLegs()
.forEach(l -> {
assertNotNull(l.accessibilityScore());
});
itinerary.getLegs().forEach(l -> assertNotNull(l.accessibilityScore()));
}

private static final List<Function<TestItineraryBuilder, TestItineraryBuilder>> nonWalkingCases = List.of(
b -> b.bicycle(10, 20, B),
b -> b.drive(10, 20, B),
b -> b.rentedBicycle(10, 20, B)
);

@FieldSource("nonWalkingCases")
@ParameterizedTest
void onlyWalking(Function<TestItineraryBuilder, TestItineraryBuilder> modifier) {
var itinerary = modifier.apply(newItinerary(A, 0)).build();
DECORATOR.decorate(itinerary);
assertNull(itinerary.getAccessibilityScore());
itinerary.getLegs().forEach(l -> assertNull(l.accessibilityScore()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private Itinerary addAccessibilityScore(Itinerary i) {
.map(leg -> {
if (leg instanceof ScheduledTransitLeg transitLeg) {
return transitLeg.withAccessibilityScore(compute(transitLeg));
} else if (leg instanceof StreetLeg streetLeg) {
} else if (leg instanceof StreetLeg streetLeg && leg.isWalkingLeg()) {
return streetLeg.withAccessibilityScore(compute(streetLeg));
} else {
return leg;
Expand Down

0 comments on commit 4b47ea2

Please sign in to comment.