|
| 1 | +package org.opentripplanner.ext.flex.flexpathcalculator; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.opentripplanner.street.model.StreetModelForTest.intersectionVertex; |
| 5 | +import static org.opentripplanner.street.model.StreetModelForTest.streetEdge; |
| 6 | + |
| 7 | +import java.time.Duration; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.opentripplanner.street.model.vertex.IntersectionVertex; |
| 10 | + |
| 11 | +class StreetFlexPathCalculatorTest { |
| 12 | + |
| 13 | + private static final int IGNORED = -99; |
| 14 | + private static final int EPSILON = 1000; |
| 15 | + private static final int EXPECTED_DISTANCE = 471_653; |
| 16 | + |
| 17 | + private final IntersectionVertex v0 = intersectionVertex(0, 0); |
| 18 | + private final IntersectionVertex v1 = intersectionVertex(1, 1); |
| 19 | + private final IntersectionVertex v2 = intersectionVertex(2, 2); |
| 20 | + private final IntersectionVertex v3 = intersectionVertex(3, 3); |
| 21 | + |
| 22 | + { |
| 23 | + streetEdge(v0, v1); |
| 24 | + streetEdge(v1, v0); |
| 25 | + streetEdge(v1, v2); |
| 26 | + streetEdge(v2, v1); |
| 27 | + streetEdge(v2, v3); |
| 28 | + streetEdge(v3, v2); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + void forward() { |
| 33 | + var forwardCalculator = new StreetFlexPathCalculator(false, Duration.ofDays(1)); |
| 34 | + var forwardPath = forwardCalculator.calculateFlexPath(v0, v3, IGNORED, IGNORED); |
| 35 | + assertEquals("LINESTRING (0 0, 1 1, 2 2, 3 3)", forwardPath.getGeometry().toString()); |
| 36 | + |
| 37 | + assertEquals(EXPECTED_DISTANCE, forwardPath.distanceMeters, EPSILON); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + void backward() { |
| 42 | + var reverseCalculator = new StreetFlexPathCalculator(true, Duration.ofDays(1)); |
| 43 | + var reversePath = reverseCalculator.calculateFlexPath(v3, v0, IGNORED, IGNORED); |
| 44 | + assertEquals("LINESTRING (3 3, 2 2, 1 1, 0 0)", reversePath.getGeometry().toString()); |
| 45 | + |
| 46 | + assertEquals(EXPECTED_DISTANCE, reversePath.distanceMeters, EPSILON); |
| 47 | + } |
| 48 | +} |
0 commit comments