Skip to content

Commit

Permalink
Fix parsing calculatedParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed Sep 5, 2019
1 parent e6d7bd6 commit d835600
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ class JaxbScalarVariable internal constructor(
override val description: String?
get() = v.description
override val causality: Causality?
get() = v.causality?.let { Causality.valueOf(it.toUpperCase()) }
get() = v.causality?.let {
var causalityString = it
val upperCaseIndex = it.indexOfFirst { it.isUpperCase() }
if (upperCaseIndex != -1) {
causalityString = causalityString.substring(0, upperCaseIndex) + "_" + causalityString.substring(upperCaseIndex, causalityString.length)
}
Causality.valueOf(causalityString.toUpperCase())
}
override val variability: Variability?
get() = v.variability?.let { Variability.valueOf(it.toUpperCase()) }
override val initial: Initial?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package no.ntnu.ihb.fmi4j.modeldescription.misc

import no.ntnu.ihb.fmi4j.modeldescription.ModelDescriptionParser
import no.ntnu.ihb.fmi4j.modeldescription.variables.Causality
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

class CalculatedParameterTest {

val xml = """
<?xml version="1.0" encoding="ISO-8859-1"?>
<fmiModelDescription fmiVersion="2.0" modelName="Test" guid="1234">
<CoSimulation modelIdentifier="test"></CoSimulation>
<ModelVariables>
<ScalarVariable name="myvar" valueReference="1" causality="calculatedParameter">
<Real />
</ScalarVariable>
</ModelVariables>
<ModelStructure>
</ModelStructure>
</fmiModelDescription>
""".trimIndent()

@Test
fun test() {

ModelDescriptionParser.parseModelDescription(xml).also {
it.asCoSimulationModelDescription().modelVariables.forEach {
Assertions.assertEquals(Causality.CALCULATED_PARAMETER, it.causality)
}
}

}

}

0 comments on commit d835600

Please sign in to comment.