Skip to content

Commit e7cf9a3

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

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private fun <T> DistanceRangeMap<T>.toRangeMap(): RangeMap<Double, T> {
422422
val res = ImmutableRangeMap.builder<Double, T>()
423423
for (entry in this) {
424424
if (entry.value != null)
425-
res.put(Range.closed(entry.lower.meters, entry.upper.meters), entry.value!!)
425+
res.put(Range.closedOpen(entry.lower.meters, entry.upper.meters), entry.value!!)
426426
}
427427
return res.build()
428428
}

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

+32-21
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
@@ -39,10 +33,10 @@ class StandaloneSimulationTest {
3933
private val infra = Helpers.tinyInfra
4034
private val routes =
4135
listOf(
42-
"rt.buffer_stop_c->tde.track-bar",
43-
"rt.tde.track-bar->tde.switch_foo-track",
44-
"rt.tde.switch_foo-track->buffer_stop_a"
45-
)
36+
"rt.buffer_stop_c->tde.track-bar",
37+
"rt.tde.track-bar->tde.switch_foo-track",
38+
"rt.tde.switch_foo-track->buffer_stop_a"
39+
)
4640
.map { infra.rawInfra.getRouteFromName(it) }
4741

4842
private val chunkPath = pathFromRoutes(infra.rawInfra, routes)
@@ -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,43 @@ class StandaloneSimulationTest {
163158
)
164159
)
165160

161+
// Power restriction values
162+
val powerRestrictionRangeMaps: List<DistanceRangeMap<String>> = listOf(
163+
distanceRangeMapOf(),
164+
distanceRangeMapOf(
165+
listOf(
166+
DistanceRangeMap.RangeMapEntry(0.meters, pathLength / 3.0, "Restrict1"),
167+
DistanceRangeMap.RangeMapEntry(pathLength / 3.0, pathLength * 2.0 / 3.0, "Restrict2"),
168+
DistanceRangeMap.RangeMapEntry(pathLength * 2.0 / 3.0, pathLength, "Restrict1")
169+
)
170+
)
171+
)
172+
166173
// List all possible combinations
167174
val res = mutableListOf<TestCase>()
168175
for (schedule in schedules) {
169176
for (margin in margins) {
170177
for (startSpeed in listOf(0.0, 15.0)) {
171178
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
179+
for (powerRestrictions in powerRestrictionRangeMaps) {
180+
res.add(
181+
TestCase(
182+
schedule = schedule,
183+
margins = margin,
184+
startSpeed = startSpeed,
185+
allowanceDistribution = distribution,
186+
pathLength = pathLength,
187+
powerRestrictions = powerRestrictions
188+
)
179189
)
180-
)
190+
}
181191
}
182192
}
183193
}
184194
}
185195
return res.map { Arguments.of(it) }.stream()
186196
}
197+
187198
/** Parametrized test, checks the interactions between margins and scheduled points */
188199
@ParameterizedTest
189200
@MethodSource("generateTestCases")
@@ -199,7 +210,7 @@ class StandaloneSimulationTest {
199210
Comfort.STANDARD,
200211
testCase.allowanceDistribution,
201212
null,
202-
distanceRangeMapOf(),
213+
testCase.powerRestrictions,
203214
false,
204215
2.0,
205216
testCase.schedule,

0 commit comments

Comments
 (0)