use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class StopTimeServiceImplTest method test02.
@Test
public void test02() {
Date dayA = getTimeAsDay(date("2009-09-01 00:00"));
Date dayB = getTimeAsDay(date("2009-09-02 00:00"));
// 10:00am, 10:30am
StopTimeEntryImpl stA = stopTime(0, _stop, trip("A", "sA"), time(10, 00), time(10, 30), 0);
// 01:00am, 01:30am (both on next day)
StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(25, 00), time(25, 30), 0);
BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip());
BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip());
addFirstStopToBlockIndex(bA, bB);
/**
**
*
***
*/
Date from = date("2009-09-01 10:10");
Date to = date("2009-09-01 10:40");
List<StopTimeInstance> results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(1, results.size());
StopTimeInstance sti = results.get(0);
assertEquals(dayA.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-01 10:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-01 10:30").getTime(), sti.getDepartureTime());
/**
**
*
***
*/
from = date("2009-09-02 10:10");
to = date("2009-09-02 10:40");
results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(1, results.size());
sti = results.get(0);
assertEquals(dayB.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
/**
**
*
***
*/
from = date("2009-09-01 10:10");
to = date("2009-09-02 10:40");
results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(3, results.size());
sti = results.get(0);
assertEquals(dayA.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-01 10:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-01 10:30").getTime(), sti.getDepartureTime());
sti = results.get(1);
assertEquals(dayA.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-02 01:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-02 01:30").getTime(), sti.getDepartureTime());
sti = results.get(2);
assertEquals(dayB.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
/**
**
*
***
*/
from = date("2009-09-01 12:00");
to = date("2009-09-02 12:00");
results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(2, results.size());
sti = results.get(0);
assertEquals(dayA.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-02 01:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-02 01:30").getTime(), sti.getDepartureTime());
sti = results.get(1);
assertEquals(dayB.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
/**
**
*
***
*/
from = date("2009-09-02 12:00");
to = date("2009-09-03 12:00");
results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(1, results.size());
sti = results.get(0);
assertEquals(dayB.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class StopTimeServiceImplTest method test03.
@Test
public void test03() {
Date dayA = getTimeAsDay(date("2009-09-02 00:00"));
Date dayB = getTimeAsDay(date("2009-09-03 00:00"));
StopTimeEntryImpl stA = stopTime(0, _stop, trip("A", "sA"), time(10, 00), time(10, 30), 0);
StopTimeEntryImpl stB = stopTime(1, _stop, trip("B", "sA"), time(25, 0), time(25, 30), 0);
StopTimeEntryImpl stC = stopTime(2, _stop, trip("C", "sB"), time(10, 00), time(10, 30), 0);
StopTimeEntryImpl stD = stopTime(3, _stop, trip("D", "sB"), time(25, 0), time(25, 30), 0);
BlockConfigurationEntry bA = linkBlockTrips("bA", stA.getTrip());
BlockConfigurationEntry bB = linkBlockTrips("bB", stB.getTrip());
BlockConfigurationEntry bC = linkBlockTrips("bC", stC.getTrip());
BlockConfigurationEntry bD = linkBlockTrips("bD", stD.getTrip());
addFirstStopToBlockIndex(bA, bB);
addFirstStopToBlockIndex(bC, bD);
/**
**
*
***
*/
Date from = date("2009-09-02 10:10");
Date to = date("2009-09-02 10:40");
List<StopTimeInstance> results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(1, results.size());
StopTimeInstance sti = results.get(0);
assertEquals(dayA.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
/**
**
*
***
*/
from = date("2009-09-03 10:10");
to = date("2009-09-03 10:40");
results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(1, results.size());
sti = results.get(0);
assertEquals(dayB.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime());
/**
**
*
***
*/
from = date("2009-09-02 10:10");
to = date("2009-09-03 10:40");
results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(3, results.size());
sti = results.get(0);
assertEquals(dayA.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-02 10:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-02 10:30").getTime(), sti.getDepartureTime());
sti = results.get(1);
assertEquals(dayA.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime());
sti = results.get(2);
assertEquals(dayB.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime());
/**
**
*
***
*/
from = date("2009-09-02 12:00");
to = date("2009-09-03 12:00");
results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(2, results.size());
sti = results.get(0);
assertEquals(dayA.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-03 01:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-03 01:30").getTime(), sti.getDepartureTime());
sti = results.get(1);
assertEquals(dayB.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-03 10:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-03 10:30").getTime(), sti.getDepartureTime());
/**
**
*
***
*/
from = date("2009-09-03 12:00");
to = date("2009-09-04 12:00");
results = _service.getStopTimeInstancesInTimeRange(_stopId, from, to);
sort(results);
assertEquals(1, results.size());
sti = results.get(0);
assertEquals(dayB.getTime(), sti.getServiceDate());
assertEquals(date("2009-09-04 01:00").getTime(), sti.getArrivalTime());
assertEquals(date("2009-09-04 01:30").getTime(), sti.getDepartureTime());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class StopTimeServiceImplTest method setup.
@Before
public void setup() {
_factory = new BlockIndexFactoryServiceImpl();
_stop = stop("stopId", 47.0, -122.0);
_stopId = _stop.getId();
TransitGraphDao graph = Mockito.mock(TransitGraphDao.class);
Mockito.when(graph.getStopEntryForId(_stop.getId(), true)).thenReturn(_stop);
CalendarServiceData data = new CalendarServiceData();
data.putDatesForLocalizedServiceId(lsid("sA"), Arrays.asList(date("2009-09-01 00:00"), date("2009-09-02 00:00")));
data.putDatesForLocalizedServiceId(lsid("sB"), Arrays.asList(date("2009-09-03 00:00")));
CalendarServiceImpl calendarService = new CalendarServiceImpl();
calendarService.setData(data);
_calendarService = new ExtendedCalendarServiceImpl();
_calendarService.setCalendarService(calendarService);
_blockIndexService = Mockito.mock(BlockIndexService.class);
_service = new StopTimeServiceImpl();
_service.setTransitGraphDao(graph);
_service.setCalendarService(_calendarService);
_service.setBlockIndexService(_blockIndexService);
BlockConfigurationEntry bcA = blockConfiguration(block("bA"), serviceIds(lsids("sA"), lsids()));
BlockConfigurationEntry bcB = blockConfiguration(block("bB"), serviceIds(lsids("sB"), lsids()));
_transitGraphDao = Mockito.mock(TransitGraphDao.class);
Mockito.when(_transitGraphDao.getAllBlocks()).thenReturn(Arrays.asList(bcA.getBlock(), bcB.getBlock()));
_calendarService.setTransitGraphDao(_transitGraphDao);
_calendarService.start();
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class StopTimeServiceImplTest method addFirstStopToBlockIndex.
/**
**
* Private Methods
***
*/
private void addFirstStopToBlockIndex(BlockConfigurationEntry... blocks) {
List<BlockTripEntry> trips = new ArrayList<BlockTripEntry>();
for (BlockConfigurationEntry blockConfig : blocks) {
trips.add(blockConfig.getTrips().get(0));
}
BlockTripIndex blockIndex = _factory.createTripIndexForGroupOfBlockTrips(trips);
BlockStopTimeIndex index = BlockStopTimeIndex.create(blockIndex, 0);
_stop.addStopTimeIndex(index);
Mockito.when(_blockIndexService.getStopTimeIndicesForStop(_stop)).thenReturn(_stop.getStopTimeIndices());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImplTest method testGetActiveBlocksInTimeRange.
@Test
public void testGetActiveBlocksInTimeRange() {
Date serviceDateA = UnitTestingSupport.date("2010-09-07 00:00");
Date serviceDateB = UnitTestingSupport.date("2010-09-08 00:00");
Date serviceDateC = UnitTestingSupport.date("2010-09-09 00:00");
UnitTestingSupport.addDates(_calendarData, "sidA", serviceDateA, serviceDateB);
UnitTestingSupport.addDates(_calendarData, "sidB", serviceDateB, serviceDateC);
ServiceIdActivation ids_A_not_B = serviceIds(lsids("sidA"), lsids("sidB"));
ServiceIdActivation ids_B_not_A = serviceIds(lsids("sidB"), lsids("sidA"));
ServiceIdActivation ids_A_and_B = serviceIds(lsids("sidA", "sidB"), lsids());
StopEntryImpl stopA = stop("stopA", 0.0, 0.0);
StopEntryImpl stopB = stop("stopB", 0.0, 0.0);
BlockEntryImpl blockA = block("blockA");
TripEntryImpl tripA = trip("tripA", "sidA");
TripEntryImpl tripB = trip("tripB", "sidB");
stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
stopTime(2, stopB, tripB, time(10, 00), time(10, 00), 200);
stopTime(3, stopA, tripB, time(10, 30), time(10, 30), 300);
linkBlockTrips(ids_A_not_B, blockA, tripA);
linkBlockTrips(ids_A_and_B, blockA, tripA, tripB);
linkBlockTrips(ids_B_not_A, blockA, tripB);
BlockConfigurationEntry bcA_A_B = findBlockConfig(blockA, ids_A_not_B);
BlockConfigurationEntry bcA_B_A = findBlockConfig(blockA, ids_B_not_A);
BlockConfigurationEntry bcA_AB = findBlockConfig(blockA, ids_A_and_B);
BlockEntryImpl blockB = block("blockB");
TripEntryImpl tripC = trip("tripC", "sidA");
TripEntryImpl tripD = trip("tripD", "sidB");
TripEntryImpl tripE = trip("tripE", "sidA");
stopTime(4, stopA, tripC, time(10, 00), time(10, 00), 0);
stopTime(5, stopB, tripC, time(10, 30), time(10, 30), 0);
stopTime(6, stopB, tripD, time(11, 00), time(11, 00), 0);
stopTime(7, stopA, tripD, time(11, 30), time(11, 30), 0);
stopTime(8, stopA, tripE, time(12, 00), time(12, 00), 0);
stopTime(9, stopB, tripE, time(12, 30), time(12, 30), 0);
linkBlockTrips(ids_A_not_B, blockB, tripC, tripE);
linkBlockTrips(ids_A_and_B, blockB, tripC, tripD, tripE);
linkBlockTrips(ids_B_not_A, blockB, tripD);
BlockConfigurationEntry bcB_A_B = findBlockConfig(blockB, ids_A_not_B);
BlockConfigurationEntry bcB_B_A = findBlockConfig(blockB, ids_B_not_A);
BlockConfigurationEntry bcB_AB = findBlockConfig(blockB, ids_A_and_B);
List<BlockTripIndex> blocks = blockTripIndices(blockA, blockB);
List<BlockLayoverIndex> layoverIndices = Collections.emptyList();
List<FrequencyBlockTripIndex> frequencyIndices = Collections.emptyList();
/**
**
*
***
*/
long time = timeFromString("2010-09-07 09:15");
List<BlockInstance> instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
BlockInstance instance = instances.get(0);
assertEquals(bcA_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-07 010:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
/*
* time = timeFromString("2010-09-07 011:15");
*
* instances = _service.getActiveBlocksInTimeRange(blocks, frequencyIndices,
* time, time);
*
* assertEquals(1, instances.size());
*
* instance = instances.get(0); assertEquals(bcB_A_B, instance.getBlock());
* assertEquals(serviceDateA.getTime(), instance.getServiceDate());
*/
/**
**
*
***
*/
time = timeFromString("2010-09-07 012:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_A_B, instance.getBlock());
assertEquals(serviceDateA.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 09:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcA_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 10:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
Collections.sort(instances, new BlockInstanceComparator());
assertEquals(2, instances.size());
instance = instances.get(0);
assertEquals(bcA_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
instance = instances.get(1);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 11:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-08 12:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_AB, instance.getBlock());
assertEquals(serviceDateB.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-09 09:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(0, instances.size());
/**
**
*
***
*/
time = timeFromString("2010-09-09 10:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcA_B_A, instance.getBlock());
assertEquals(serviceDateC.getTime(), instance.getServiceDate());
/**
**
*
***
*/
time = timeFromString("2010-09-09 11:15");
instances = _service.getActiveBlocksInTimeRange(blocks, layoverIndices, frequencyIndices, time, time);
assertEquals(1, instances.size());
instance = instances.get(0);
assertEquals(bcB_B_A, instance.getBlock());
assertEquals(serviceDateC.getTime(), instance.getServiceDate());
}
Aggregations