Skip to content

Commit

Permalink
core: replace MinPerKm with MinPer100Km
Browse files Browse the repository at this point in the history
  • Loading branch information
younesschrifi committed May 16, 2024
1 parent b08805c commit 9188fd9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SimulationScheduleItem(
)

sealed class MarginValue {
class MinPerKm(var value: Double) : MarginValue()
class MinPer100Km(var value: Double) : MarginValue()

class Percentage(var percentage: Double) : MarginValue()

Expand All @@ -108,7 +108,7 @@ class MarginValueAdapter {
@ToJson
fun toJson(value: MarginValue): String {
return when (value) {
is MarginValue.MinPerKm -> {
is MarginValue.MinPer100Km -> {
"${value.value}min/km"
}
is MarginValue.Percentage -> {
Expand All @@ -131,7 +131,7 @@ class MarginValueAdapter {
}
if (marginValue.endsWith("min/km")) {
val minPerKm = marginValue.split("min/km")[0].toDouble()
return MarginValue.MinPerKm(minPerKm)
return MarginValue.MinPer100Km(minPerKm)
}
throw JsonDataException("Margin value type not recognized $marginValue")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private fun parseSteps(infra: FullInfra, pathItems: List<STDCMPathItem>): List<S

private fun parseMarginValue(margin: MarginValue): AllowanceValue? {
return when (margin) {
is MarginValue.MinPerKm -> {
is MarginValue.MinPer100Km -> {
TimePerDistance(margin.value * 100)
}
is MarginValue.Percentage -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ fun buildProvisionalEnvelope(
val end = boundaries[i + 1]
val value =
when (val rawValue = rawMargins.values[i]) {
is MarginValue.MinPerKm -> TimePerDistance(rawValue.value)
is MarginValue.MinPer100Km -> TimePerDistance(rawValue.value)
is MarginValue.Percentage -> Percentage(rawValue.percentage)
is MarginValue.None -> Percentage(0.0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class StandaloneSimulationTest {
listOf(pathLength.distance / 2.0),
listOf(
MarginValue.Percentage(10.0),
MarginValue.MinPerKm(5.0),
MarginValue.MinPer100Km(5.0),
),
)
)
Expand Down Expand Up @@ -238,7 +238,7 @@ class StandaloneSimulationTest {
getTimeAt(entryOffset, res.provisional, true)
val value =
when (val rawValue = testCase.margins.values[i]) {
is MarginValue.MinPerKm -> TimePerDistance(rawValue.value)
is MarginValue.MinPer100Km -> TimePerDistance(rawValue.value)
is MarginValue.Percentage -> Percentage(rawValue.percentage)
is MarginValue.None -> Percentage(0.0)
}
Expand Down

0 comments on commit 9188fd9

Please sign in to comment.