public class StreetfulStopLinkerTest {
@Test
public final void testStreetfulStopLinker() {
final double speed = new RoutingRequest().walkSpeed;
Graph graph = new Graph();
Stop stopA = new Stop();
Stop stopB = new Stop();
Stop stopC = new Stop();
Stop stopD = new Stop();
Stop stopE = new Stop();
stopA.setId(new AgencyAndId("Stop", "A"));
stopA.setLon(0);
stopA.setLat(0);
stopB.setId(new AgencyAndId("Stop", "B"));
stopB.setLon(0);
stopB.setLat(3);
stopC.setId(new AgencyAndId("Stop", "C"));
stopC.setLon(3);
stopC.setLat(3);
stopD.setId(new AgencyAndId("Stop", "D"));
stopD.setLon(3);
stopD.setLat(0);
stopE.setId(new AgencyAndId("Stop", "E"));
stopE.setLon(2);
stopE.setLat(2);
TransitStop transitStopA = new TransitStop(graph, stopA);
TransitStop transitStopB = new TransitStop(graph, stopB);
TransitStop transitStopC = new TransitStop(graph, stopC);
TransitStop transitStopD = new TransitStop(graph, stopD);
TransitStop transitStopE = new TransitStop(graph, stopE);
IntersectionVertex intersectionA = new IntersectionVertex(graph, "Intersection A", 1, 1);
IntersectionVertex intersectionB = new IntersectionVertex(graph, "Intersection B", 1, 2);
IntersectionVertex intersectionC = new IntersectionVertex(graph, "Intersection C", 2, 2);
IntersectionVertex intersectionD = new IntersectionVertex(graph, "Intersection D", 2, 1);
intersectionA.freeFlowing = (true);
intersectionB.freeFlowing = (true);
intersectionC.freeFlowing = (true);
intersectionD.freeFlowing = (true);
new StreetTransitLink(transitStopA, intersectionA, true);
new StreetTransitLink(intersectionB, transitStopB, true);
new StreetTransitLink(intersectionC, transitStopC, true);
new StreetTransitLink(intersectionD, transitStopD, true);
new StreetTransitLink(intersectionA, transitStopE, true);
PackedCoordinateSequence coordinatesAB = new PackedCoordinateSequence.Double(
new double[]{1, 1, 1, 2}, 2);
PackedCoordinateSequence coordinatesBC = new PackedCoordinateSequence.Double(
new double[]{1, 2, 2, 2}, 2);
PackedCoordinateSequence coordinatesCD = new PackedCoordinateSequence.Double(
new double[]{2, 2, 2, 1}, 2);
PackedCoordinateSequence coordinatesAD = new PackedCoordinateSequence.Double(
new double[]{1, 1, 2, 1}, 2);
GeometryFactory geometryFactory = new GeometryFactory();
LineString lineStringAB = new LineString(coordinatesAB, geometryFactory);
LineString lineStringBC = new LineString(coordinatesBC, geometryFactory);
LineString lineStringCD = new LineString(coordinatesCD, geometryFactory);
LineString lineStringAD = new LineString(coordinatesAD, geometryFactory);
// Powers of 2 avoid complications related to floating point arithmetic
new StreetEdge(intersectionA, intersectionB, lineStringAB, "Edge AB", 2 * speed,
StreetTraversalPermission.ALL, false);
new StreetEdge(intersectionB, intersectionC, lineStringBC, "Edge BC", 4 * speed,
StreetTraversalPermission.ALL, false);
new StreetEdge(intersectionC, intersectionD, lineStringCD, "Edge CD", 8 * speed,
StreetTraversalPermission.ALL, false);
new StreetEdge(intersectionA, intersectionD, lineStringAD, "Edge AD", 16 * speed,
StreetTraversalPermission.ALL, false);
StreetfulStopLinker streetfulStopLinker = new StreetfulStopLinker();
assertEquals(9, graph.countVertices());
assertEquals(9, graph.countEdges());
// The duration of the shortest path (A => E) is 2 seconds
streetfulStopLinker.maxDuration = 1;
streetfulStopLinker.buildGraph(graph, null);
assertEquals(9, graph.countEdges());
// The duration of the longest path (A => D) is 16 seconds
streetfulStopLinker.maxDuration = 18;
streetfulStopLinker.buildGraph(graph, null);
assertEquals(13, graph.countEdges());
assertEquals(9, graph.countVertices());
final double results[] = new double[4];
for (Edge edge : graph.getEdges()) {
if (edge instanceof SimpleTransfer) {
assertEquals(transitStopA, edge.getFromVertex());
assertNotSame(transitStopA, edge.getToVertex());
double EPSILON_D = 0.1;
if (edge.getToVertex().equals(transitStopB)) {