Skip to content

Commit 62c072a

Browse files
committed
core: fix distance_range_map.to_range_map
1 parent d420d30 commit 62c072a

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

core/src/main/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulation.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ fun getStopPositions(schedule: List<SimulationScheduleItem>): List<Double> {
414414
return schedule.filter { it.stopFor != null }.map { it.pathOffset.distance.meters }
415415
}
416416

417+
// TODO: Get rid of this function, by propagating DistanceRangeMap to the whole codebase
417418
/**
418419
* Converts a DistanceRangeMap<T> into a legacy RangeMap<Double, T>. Distances are converted to
419420
* floats (m).
@@ -422,7 +423,7 @@ private fun <T> DistanceRangeMap<T>.toRangeMap(): RangeMap<Double, T> {
422423
val res = ImmutableRangeMap.builder<Double, T>()
423424
for (entry in this) {
424425
if (entry.value != null)
425-
res.put(Range.closed(entry.lower.meters, entry.upper.meters), entry.value!!)
426+
res.put(Range.closedOpen(entry.lower.meters, entry.upper.meters), entry.value!!)
426427
}
427428
return res.build()
428429
}

core/src/test/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulationTest.kt

+37-17
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@ import fr.sncf.osrd.railjson.schema.rollingstock.Comfort
1818
import fr.sncf.osrd.railjson.schema.schedule.RJSAllowanceDistribution
1919
import fr.sncf.osrd.sim_infra.api.makePathProperties
2020
import fr.sncf.osrd.train.TestTrains
21-
import fr.sncf.osrd.utils.Helpers
22-
import fr.sncf.osrd.utils.distanceRangeMapOf
23-
import fr.sncf.osrd.utils.pathFromRoutes
24-
import fr.sncf.osrd.utils.toIdxList
25-
import fr.sncf.osrd.utils.units.Distance
26-
import fr.sncf.osrd.utils.units.Offset
27-
import fr.sncf.osrd.utils.units.TimeDelta
28-
import fr.sncf.osrd.utils.units.seconds
21+
import fr.sncf.osrd.utils.*
22+
import fr.sncf.osrd.utils.units.*
2923
import java.util.stream.Stream
3024
import kotlin.test.assertEquals
3125
import org.junit.jupiter.api.Test
@@ -99,6 +93,7 @@ class StandaloneSimulationTest {
9993
val startSpeed: Double = 0.0,
10094
val margins: RangeValues<MarginValue> = RangeValues(),
10195
val pathLength: Distance,
96+
val powerRestrictions: DistanceRangeMap<String> = distanceRangeMapOf()
10297
)
10398

10499
/**
@@ -163,27 +158,52 @@ class StandaloneSimulationTest {
163158
)
164159
)
165160

161+
// Power restriction values
162+
val powerRestrictionRangeMaps: List<DistanceRangeMap<String>> =
163+
listOf(
164+
distanceRangeMapOf(),
165+
distanceRangeMapOf(
166+
listOf(
167+
DistanceRangeMap.RangeMapEntry(0.meters, pathLength / 3.0, "Restrict1"),
168+
DistanceRangeMap.RangeMapEntry(
169+
pathLength / 3.0,
170+
pathLength * 2.0 / 3.0,
171+
"Restrict2"
172+
),
173+
DistanceRangeMap.RangeMapEntry(
174+
pathLength * 2.0 / 3.0,
175+
pathLength,
176+
"Restrict1"
177+
)
178+
)
179+
)
180+
)
181+
166182
// List all possible combinations
167183
val res = mutableListOf<TestCase>()
168184
for (schedule in schedules) {
169185
for (margin in margins) {
170186
for (startSpeed in listOf(0.0, 15.0)) {
171187
for (distribution in RJSAllowanceDistribution.entries) {
172-
res.add(
173-
TestCase(
174-
schedule = schedule,
175-
margins = margin,
176-
startSpeed = startSpeed,
177-
allowanceDistribution = distribution,
178-
pathLength = pathLength
188+
for (powerRestrictions in powerRestrictionRangeMaps) {
189+
res.add(
190+
TestCase(
191+
schedule = schedule,
192+
margins = margin,
193+
startSpeed = startSpeed,
194+
allowanceDistribution = distribution,
195+
pathLength = pathLength,
196+
powerRestrictions = powerRestrictions
197+
)
179198
)
180-
)
199+
}
181200
}
182201
}
183202
}
184203
}
185204
return res.map { Arguments.of(it) }.stream()
186205
}
206+
187207
/** Parametrized test, checks the interactions between margins and scheduled points */
188208
@ParameterizedTest
189209
@MethodSource("generateTestCases")
@@ -199,7 +219,7 @@ class StandaloneSimulationTest {
199219
Comfort.STANDARD,
200220
testCase.allowanceDistribution,
201221
null,
202-
distanceRangeMapOf(),
222+
testCase.powerRestrictions,
203223
false,
204224
2.0,
205225
testCase.schedule,

0 commit comments

Comments
 (0)