use of org.opentripplanner.model.plan.Itinerary in project OpenTripPlanner by opentripplanner.
the class LatestDepartureTimeFilterTest method filterOnLatestDepartureTime.
@Test
public void filterOnLatestDepartureTime() {
// Given:
Itinerary it = newItinerary(A).bus(32, 0, 60, E).build();
Instant time = it.firstLeg().startTime.toInstant();
// When:
assertTrue(new LatestDepartureTimeFilter(time.minusSeconds(1)).filter(List.of(it)).isEmpty());
assertFalse(new LatestDepartureTimeFilter(time).filter(List.of(it)).isEmpty());
}
use of org.opentripplanner.model.plan.Itinerary in project OpenTripPlanner by opentripplanner.
the class OtpDefaultSortOrderTest method sortStreetBeforeTransitThenTime.
@Test
public void sortStreetBeforeTransitThenTime() {
Itinerary walk = newItinerary(A, 0).walk(5, G).build();
Itinerary bicycle = newItinerary(B).bicycle(4, 6, G).build();
Itinerary bus = newItinerary(C).bus(21, 1, 4, G).build();
Itinerary rail = newItinerary(D).rail(21, 3, 7, G).build();
// Eliminate cost
walk.generalizedCost = bicycle.generalizedCost = bus.generalizedCost = rail.generalizedCost = 0;
// Depart-after-sort
result = departAfterSort().filter(List.of(walk, bicycle, bus, rail));
assertEquals(toStr(walk, bicycle, bus, rail), toStr(result));
// Arrive-by-sort
result = arriveBySort().filter(List.of(walk, bicycle, bus, rail));
assertEquals(toStr(bicycle, walk, rail, bus), toStr(result));
}
use of org.opentripplanner.model.plan.Itinerary in project OpenTripPlanner by opentripplanner.
the class OtpDefaultSortOrderTest method sortOnGeneralizedCostVsNumberOfTransfers.
@Test
public void sortOnGeneralizedCostVsNumberOfTransfers() {
// Best cost, 1 transfer
Itinerary iA = newItinerary(A).bus(11, 0, 20, C).bus(21, 22, 40, G).build();
iA.generalizedCost = 1;
// Same cost, more transfers (2 transfers)
Itinerary iB = newItinerary(B).bus(11, 0, 10, C).bus(21, 12, 20, D).bus(31, 22, 40, G).build();
iB.generalizedCost = 1;
// Worse on cost, better on transfers
Itinerary iC = newItinerary(C).bus(11, 0, 40, G).build();
iC.generalizedCost = 100;
// Verify depart-after sort on generalized-cost, then transfers
assertEquals(toStr(iA, iB, iC), toStr(departAfterSort().filter(List.of(iB, iC, iA))));
// Verify arrive-by sort on generalized-cost, then transfers
assertEquals(toStr(iA, iB, iC), toStr(arriveBySort().filter(List.of(iC, iA, iB))));
}
use of org.opentripplanner.model.plan.Itinerary in project OpenTripPlanner by opentripplanner.
the class OtpDefaultSortOrderTest method sortOnGeneralizedCostVsTime.
@Test
public void sortOnGeneralizedCostVsTime() {
Itinerary iA = newItinerary(A).bus(21, 0, 20, G).build();
iA.generalizedCost = 1;
// Better on arrival-time, but worse on cost
Itinerary iB = newItinerary(B).bus(21, 0, 10, G).build();
iB.generalizedCost = 100;
// Better on departure-time, but worse on cost
Itinerary iC = newItinerary(C).bus(21, 10, 20, G).build();
iC.generalizedCost = 100;
// Verify depart-after sort on arrival-time, then cost
assertEquals(toStr(iB, iA, iC), toStr(departAfterSort().filter(List.of(iB, iA, iC))));
// Verify arrive-by sort on departure-time, then cost
assertEquals(toStr(iC, iA, iB), toStr(arriveBySort().filter(List.of(iB, iA, iC))));
}
use of org.opentripplanner.model.plan.Itinerary in project OpenTripPlanner by opentripplanner.
the class GroupByTripIdAndDistanceTest method getKeySetOfLegsByLimitTest.
@Test
public void getKeySetOfLegsByLimitTest() {
Itinerary i = newItinerary(A).bus(11, 0, 5, B).bus(21, 10, 12, C).bus(31, 20, 23, D).build();
Leg l1 = i.legs.get(0);
Leg l2 = i.legs.get(1);
Leg l3 = i.legs.get(2);
Double d1 = l1.distanceMeters;
Double d3 = l3.distanceMeters;
// These test relay on the internal sort by distance, witch make the implementation
// a bit simpler, but strictly is not something the method grantees
assertEquals(List.of(l1), getKeySetOfLegsByLimit(List.of(l1, l2, l3), d1 - 0.01));
assertEquals(List.of(l1, l3), getKeySetOfLegsByLimit(List.of(l1, l2, l3), d1 + 0.01));
assertEquals(List.of(l1, l3), getKeySetOfLegsByLimit(List.of(l1, l2, l3), d1 + d3 - 0.01));
assertEquals(List.of(l1, l3, l2), getKeySetOfLegsByLimit(List.of(l1, l2, l3), d1 + d3 + 0.01));
}
Aggregations