Skip to content

Commit

Permalink
fixup! tests: add integration tests for arrival on stop signal
Browse files Browse the repository at this point in the history
  • Loading branch information
woshilapin authored and bougue-pe committed May 30, 2024
1 parent c4f4f8d commit 2a666fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private class InfraExplorerImpl(
val isRouteBlocked =
constraints.any { constraint -> constraint.apply(block).isNotEmpty() }
if (isRouteBlocked) return false
val endPath = stops.last().any { it.edge == block }
val endPath = stops.isNotEmpty() && stops.last().any { it.edge == block }
val startPath = !pathStarted
val addRoute = block == routeBlocks.first() || startPath
pathFragments.add(
Expand Down Expand Up @@ -327,15 +327,15 @@ private class InfraExplorerImpl(
}

private fun findStopsOnBlock(block: StaticIdx<Block>): List<PathStop> {
val pathStops = mutableListOf<PathStop>()
if (incrementalPath.blockCount < 1) return listOf()
for (stop in stops) {
for (location in stop) {
if (location.edge == block) {
pathStops.add(PathStop(incrementalPath.getBlockPathEnd(), true))
return listOf(PathStop(incrementalPath.getBlockPathEnd(), true))
}
}
}
return pathStops
return listOf()
}

override fun toString(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import fr.sncf.osrd.utils.DummyInfra
import fr.sncf.osrd.utils.Helpers
import fr.sncf.osrd.utils.units.Offset
import fr.sncf.osrd.utils.units.meters
import fr.sncf.osrd.utils.units.sumOffsets
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
Expand All @@ -27,13 +28,14 @@ class InfraExplorerTests {
*/
val infra = DummyInfra()
val block = infra.addBlock("a", "b")
val endOffset = infra.getBlockLength(block)

val explorers =
initInfraExplorer(
infra,
infra,
PathfindingEdgeLocationId(block, Offset(0.meters)),
listOf(block)
listOf(setOf(PathfindingEdgeLocationId(block, endOffset)))
)
assertEquals(1, explorers.size)
val explorer = explorers.first()
Expand All @@ -54,14 +56,15 @@ class InfraExplorerTests {
infra.addBlock("c", "d"),
infra.addBlock("d", "e"),
)
val endOffset = blocks.map { infra.getBlockLength(it) }.sumOffsets()

// a --> b
val firstExplorers =
initInfraExplorer(
infra,
infra,
PathfindingEdgeLocationId(blocks[0], Offset(0.meters)),
listOf(blocks.last())
listOf(setOf(PathfindingEdgeLocationId(blocks.last(), endOffset)))
)
assertEquals(1, firstExplorers.size)
var explorer = firstExplorers.first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import fr.sncf.osrd.utils.Direction
import fr.sncf.osrd.utils.Helpers
import fr.sncf.osrd.utils.units.Offset
import fr.sncf.osrd.utils.units.meters
import fr.sncf.osrd.utils.units.sumOffsets
import kotlin.Double.Companion.POSITIVE_INFINITY
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -109,11 +110,12 @@ class BlockAvailabilityTests {
assert(nBlocksInPath >= nBlocksSimulated)
assert(nBlocksInPath <= 5)

val endOffset = blocks.map { infra.blockInfra.getBlockLength(it) }.sumOffsets()
var infraExplorer =
initInfraExplorerWithEnvelope(
infra,
PathfindingEdgeLocationId(blocks[0], Offset(0.meters)),
listOf(blocks.last()),
listOf(setOf(PathfindingEdgeLocationId(blocks.last(), endOffset))),
rollingStock
)
.find { filterExplorer(it) }!!
Expand Down Expand Up @@ -583,11 +585,12 @@ class BlockAvailabilityTests {
*/
@Test
fun testNotStartingOnRouteFirstBlock() {
val endOffset = blocks.map { infra.blockInfra.getBlockLength(it) }.sumOffsets()
var explorer =
initInfraExplorerWithEnvelope(
infra,
PathfindingEdgeLocationId(blocks[2], Offset(50.meters)),
listOf(blocks.last()),
listOf(setOf(PathfindingEdgeLocationId(blocks.last(), endOffset))),
REALISTIC_FAST_TRAIN
)
.first { filterExplorer(it) }
Expand Down

0 comments on commit 2a666fc

Please sign in to comment.