Skip to content

Commit b4520ad

Browse files
Add test for vertex linker
1 parent df1f564 commit b4520ad

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

application/src/main/java/org/opentripplanner/routing/linking/VertexLinker.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,7 @@ private StreetVertex snapAndLink(
425425
}
426426

427427
if (OTPFeature.FlexRouting.isOn()) {
428-
var areaStops = Stream.concat(
429-
start.getIncomingStreetEdges().stream(),
430-
start.getOutgoing().stream()
431-
)
428+
var areaStops = Stream.concat(start.getIncoming().stream(), start.getOutgoing().stream())
432429
.flatMap(e ->
433430
Stream.concat(
434431
e.getFromVertex().areaStops().stream(),
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,64 @@
11
package org.opentripplanner.routing.linking;
22

3-
import static org.junit.jupiter.api.Assertions.*;
3+
import static com.google.common.truth.Truth.assertThat;
44

5+
import java.util.List;
6+
import java.util.Set;
57
import org.junit.jupiter.api.Test;
8+
import org.opentripplanner.framework.application.OTPFeature;
69
import org.opentripplanner.routing.graph.Graph;
710
import org.opentripplanner.street.model._data.StreetModelForTest;
8-
import org.opentripplanner.test.support.GeoJsonIo;
11+
import org.opentripplanner.street.model.edge.LinkingDirection;
12+
import org.opentripplanner.street.model.vertex.SplitterVertex;
13+
import org.opentripplanner.street.model.vertex.StreetVertex;
14+
import org.opentripplanner.street.search.TraverseModeSet;
15+
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
16+
import org.opentripplanner.transit.model.site.AreaStop;
917

1018
class VertexLinkerTest {
1119

20+
public static final TimetableRepositoryForTest REPO = TimetableRepositoryForTest.of();
21+
public static final AreaStop AREA_STOP_1 = REPO.areaStop("area-stop-1").build();
22+
public static final AreaStop AREA_STOP_2 = REPO.areaStop("area-stop-2").build();
23+
1224
@Test
1325
void flex() {
14-
var v1 = StreetModelForTest.intersectionVertex(0, 0);
15-
var v2 = StreetModelForTest.intersectionVertex(0.1, 0.1);
16-
var edge = StreetModelForTest.streetEdge(v1, v2);
26+
OTPFeature.FlexRouting.testOn(() -> {
27+
var v1 = StreetModelForTest.intersectionVertex(0, 0);
28+
v1.addAreaStops(Set.of(AREA_STOP_1));
29+
var v2 = StreetModelForTest.intersectionVertex(0.1, 0.1);
30+
v2.addAreaStops(Set.of(AREA_STOP_2));
31+
32+
var toBeLinked = StreetModelForTest.intersectionVertex(0.05, 0.06);
33+
34+
assertThat(toBeLinked.areaStops()).isEmpty();
35+
36+
StreetModelForTest.streetEdge(v1, v2);
37+
38+
var graph = new Graph();
39+
40+
graph.addVertex(v1);
41+
graph.addVertex(v2);
42+
graph.index();
43+
44+
var linker = new VertexLinker(graph);
1745

18-
var graph = new Graph();
46+
linker.linkVertexPermanently(
47+
toBeLinked,
48+
TraverseModeSet.allModes(),
49+
LinkingDirection.BIDIRECTIONAL,
50+
(vertex, streetVertex) ->
51+
List.of(
52+
StreetModelForTest.streetEdge((StreetVertex) vertex, streetVertex),
53+
StreetModelForTest.streetEdge(streetVertex, (StreetVertex) vertex)
54+
)
55+
);
1956

20-
graph.addVertex(v1);
21-
graph.addVertex(v2);
22-
graph.index();
57+
var splitterVertices = graph.getVerticesOfType(SplitterVertex.class);
58+
assertThat(splitterVertices).hasSize(1);
59+
var splitter = splitterVertices.getFirst();
2360

24-
System.out.println(GeoJsonIo.toUrl(graph));
61+
assertThat(splitter.areaStops()).containsExactly(AREA_STOP_1, AREA_STOP_2);
62+
});
2563
}
2664
}

0 commit comments

Comments
 (0)