Skip to content

Commit

Permalink
Add test for idempotency
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Nov 13, 2023
1 parent 86ad821 commit 348dedb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ private enum StopLinkType {
*/
WALK_ONLY,
/**
* Make sure that the stop is linked to an edge that is both walkable and drivable which is
* required if the stop used by a flex trip.
* Make sure that the stop is linked to an edge each that is walkable and drivable.
* This may lead to several links being created.
*/
WALK_AND_CAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ class StreetLinkerModuleTest {

private static final double DELTA = 0.0001;

@Test
void linkingIsIdempotent() {
var model = new TestModel();
var module = model.streetLinkerModule();

module.buildGraph();
module.buildGraph();
module.buildGraph();

assertTrue(model.stopVertex().isConnectedToGraph());
assertEquals(1, model.stopVertex().getOutgoing().size());
}

@Test
void linkRegularStop() {
var model = new TestModel();
Expand All @@ -42,7 +55,7 @@ void linkRegularStop() {
assertTrue(model.stopVertex().isConnectedToGraph());

assertEquals(1, model.stopVertex().getOutgoing().size());
var outgoing = model.outgoingLinks().get(0);
var outgoing = model.outgoingLinks().getFirst();
assertInstanceOf(StreetTransitStopLink.class, outgoing);

SplitterVertex linkedTo = (SplitterVertex) outgoing.getToVertex();
Expand All @@ -66,13 +79,13 @@ void linkFlexStop() {

// stop is used by a flex trip, needs to be linked to both the walk and car edge
assertEquals(2, model.stopVertex().getOutgoing().size());
var linkToWalk = model.outgoingLinks().get(0);
var linkToWalk = model.outgoingLinks().getFirst();
SplitterVertex walkSplit = (SplitterVertex) linkToWalk.getToVertex();

assertTrue(walkSplit.isConnectedToWalkingEdge());
assertFalse(walkSplit.isConnectedToDriveableEdge());

var linkToCar = model.outgoingLinks().get(1);
var linkToCar = model.outgoingLinks().getLast();
SplitterVertex carSplit = (SplitterVertex) linkToCar.getToVertex();

assertFalse(carSplit.isConnectedToWalkingEdge());
Expand Down

0 comments on commit 348dedb

Please sign in to comment.