Skip to content

Commit

Permalink
always include a walk/vehicleRentalState=null state in initial states
Browse files Browse the repository at this point in the history
  • Loading branch information
tkalvas committed Nov 8, 2024
1 parent 5e7b3a6 commit 987d204
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static VehicleRentalEdge createVehicleRentalEdge(

@Override
public State[] traverse(State s0) {
if (!s0.getRequest().mode().includesRenting()) {
if (!s0.getRequest().mode().includesRenting() || s0.getVehicleRentalState() == null) {
return State.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ public State[] traverse(State s0) {
final StateEditor editor;

final boolean arriveByRental =
s0.getRequest().mode().includesRenting() && s0.getRequest().arriveBy();
s0.getRequest().mode().includesRenting() &&
s0.getRequest().arriveBy() &&
s0.getVehicleRentalState() != null;
if (arriveByRental && tov.rentalTraversalBanned(s0)) {
return State.empty();
} else if (arriveByRental && hasStartedWalkingInNoDropOffZoneAndIsExitingIt(s0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ else if (requestMode.includesRenting()) {
stationReturnedStateData.vehicleRentalState = HAVE_RENTED;
stationReturnedStateData.currentMode = TraverseMode.WALK;
res.add(stationReturnedStateData);
res.add(proto.clone());
} else {
var beforeRentalStateData = proto.clone();
beforeRentalStateData.vehicleRentalState = BEFORE_RENTING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ public void testNoBikesAvailable() {
"null - BEFORE_RENTING - E1 (1,656.14, 828)"
),
List.of(
"WALK - HAVE_RENTED - AB street (76.19, 38)",
"WALK - HAVE_RENTED - BC street (1,579.95, 790)",
"WALK - HAVE_RENTED - CD street (1,655.14, 828)",
"null - HAVE_RENTED - E1 (1,656.14, 828)"
"WALK - null - AB street (76.19, 38)",
"WALK - null - BC street (1,579.95, 790)",
"WALK - null - CD street (1,655.14, 828)",
"null - null - E1 (1,656.14, 828)"
)
);
}
Expand Down Expand Up @@ -450,7 +450,7 @@ private void assertNoRental(
);

assertEquals(
List.of("WALK - HAVE_RENTED - BC street (1,503.76, 752)"),
List.of("WALK - null - BC street (1,503.76, 752)"),
runStreetSearchAndCreateDescriptor(fromVertex, toVertex, true, setter),
"arriveBy"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,24 @@ class StateTest {
NULL_RENTAL_STATES.add(null);
}

static Set<VehicleRentalState> setOfWithNull(VehicleRentalState... states) {
var set = new HashSet<VehicleRentalState>();
set.add(null);
for (var state : states) {
set.add(state);
}
return set;
}

static Stream<Arguments> testCases() {
return Stream.of(
of(SCOOTER_RENTAL, false, Set.of(BEFORE_RENTING), Set.of(WALK)),
//FIXME: it's strange that the arriveBy rental searches all start on a bicycle
of(SCOOTER_RENTAL, true, Set.of(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)),
of(SCOOTER_RENTAL, true, setOfWithNull(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)),
of(BIKE_RENTAL, false, Set.of(BEFORE_RENTING), Set.of(WALK)),
of(BIKE_RENTAL, true, Set.of(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)),
of(BIKE_RENTAL, true, setOfWithNull(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)),
of(CAR_RENTAL, false, Set.of(BEFORE_RENTING), Set.of(WALK)),
of(CAR_RENTAL, true, Set.of(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)),
of(CAR_RENTAL, true, setOfWithNull(HAVE_RENTED, RENTING_FLOATING), Set.of(WALK, BICYCLE)),
of(StreetMode.CAR, false, NULL_RENTAL_STATES, Set.of(CAR)),
of(BIKE, false, NULL_RENTAL_STATES, Set.of(BICYCLE)),
of(StreetMode.WALK, false, NULL_RENTAL_STATES, Set.of(TraverseMode.WALK)),
Expand Down

0 comments on commit 987d204

Please sign in to comment.