Search in sources :

Example 1 with ServiceDateInterval

use of org.opentripplanner.model.calendar.ServiceDateInterval in project OpenTripPlanner by opentripplanner.

the class OtpTransitServiceBuilderLimitPeriodTest method testLimitPeriod.

@Test
public void testLimitPeriod() {
    // Assert the test is set up as expected
    assertEquals(2, subject.getCalendars().size());
    assertEquals(2, subject.getCalendarDates().size());
    assertEquals(4, subject.getTripsById().size());
    assertEquals(3, subject.getTripPatterns().get(STOP_PATTERN).size());
    assertEquals(2, patternInT1.getTrips().size());
    assertEquals(2, patternInT1.scheduledTimetable.tripTimes.size());
    assertEquals(1, patternInT2.getTrips().size());
    assertEquals(1, patternInT2.scheduledTimetable.tripTimes.size());
    // Limit service to last half of month
    subject.limitServiceDays(new ServiceDateInterval(D2, D3));
    // Verify calendar
    List<ServiceCalendar> calendars = subject.getCalendars();
    assertEquals(calendars.toString(), 1, calendars.size());
    assertEquals(calendars.toString(), SERVICE_C_IN, calendars.get(0).getServiceId());
    // Verify calendar dates
    List<ServiceCalendarDate> dates = subject.getCalendarDates();
    assertEquals(dates.toString(), 1, dates.size());
    assertEquals(dates.toString(), SERVICE_D_IN, dates.get(0).getServiceId());
    // Verify trips
    EntityById<FeedScopedId, Trip> trips = subject.getTripsById();
    assertEquals(trips.toString(), 2, trips.size());
    assertTrue(trips.toString(), trips.containsKey(tripCSIn.getId()));
    assertTrue(trips.toString(), trips.containsKey(tripCSDIn.getId()));
    // Verify patterns
    Collection<TripPattern> patterns = subject.getTripPatterns().get(STOP_PATTERN);
    assertEquals(2, patterns.size());
    assertTrue(patterns.toString(), patterns.contains(patternInT1));
    assertTrue(patterns.toString(), patterns.contains(patternInT2));
    // Verify trips in pattern (one trip is removed from patternInT1)
    assertEquals(1, patternInT1.getTrips().size());
    assertEquals(tripCSIn, patternInT1.getTrips().get(0));
    // Verify trips in pattern is unchanged (one trip)
    assertEquals(1, patternInT2.getTrips().size());
    // Verify scheduledTimetable trips (one trip is removed from patternInT1)
    assertEquals(1, patternInT1.scheduledTimetable.tripTimes.size());
    assertEquals(tripCSIn, patternInT1.scheduledTimetable.tripTimes.get(0).trip);
    // Verify scheduledTimetable trips in pattern is unchanged (one trip)
    assertEquals(1, patternInT2.scheduledTimetable.tripTimes.size());
}
Also used : ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) Trip(org.opentripplanner.model.Trip) ServiceDateInterval(org.opentripplanner.model.calendar.ServiceDateInterval) FeedScopedId(org.opentripplanner.model.FeedScopedId) TripPattern(org.opentripplanner.model.TripPattern) ServiceCalendar(org.opentripplanner.model.calendar.ServiceCalendar) Test(org.junit.Test)

Example 2 with ServiceDateInterval

use of org.opentripplanner.model.calendar.ServiceDateInterval in project OpenTripPlanner by opentripplanner.

the class OtpTransitServiceBuilderLimitPeriodTest method createServiceCalendar.

private static ServiceCalendar createServiceCalendar(FeedScopedId serviceId, ServiceDate start, ServiceDate end) {
    ServiceCalendar calendar = new ServiceCalendar();
    calendar.setPeriod(new ServiceDateInterval(start, end));
    calendar.setAllDays(1);
    calendar.setServiceId(serviceId);
    return calendar;
}
Also used : ServiceDateInterval(org.opentripplanner.model.calendar.ServiceDateInterval) ServiceCalendar(org.opentripplanner.model.calendar.ServiceCalendar)

Aggregations

ServiceCalendar (org.opentripplanner.model.calendar.ServiceCalendar)2 ServiceDateInterval (org.opentripplanner.model.calendar.ServiceDateInterval)2 Test (org.junit.Test)1 FeedScopedId (org.opentripplanner.model.FeedScopedId)1 Trip (org.opentripplanner.model.Trip)1 TripPattern (org.opentripplanner.model.TripPattern)1 ServiceCalendarDate (org.opentripplanner.model.calendar.ServiceCalendarDate)1