visionforge/visionforge-gdml/src/commonTest/kotlin/TestCubes.kt

65 lines
2.1 KiB
Kotlin
Raw Normal View History

2021-03-07 16:19:43 +03:00
package space.kscience.visionforge.gdml
2021-03-01 19:10:15 +03:00
2021-03-07 16:19:43 +03:00
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.names.toName
2021-05-05 15:28:06 +03:00
import space.kscience.gdml.*
2021-03-07 16:19:43 +03:00
import space.kscience.visionforge.Vision
import space.kscience.visionforge.get
import space.kscience.visionforge.solid.*
import space.kscience.visionforge.visionManager
2021-03-01 19:10:15 +03:00
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
internal val testContext = Context("TEST") {
plugin(Solids)
}
class TestCubes {
2021-05-05 15:28:06 +03:00
val cubes = GdmlShowCase.cubes()
2021-03-01 19:10:15 +03:00
@Test
fun testCubesDirect() {
val vision = cubes.toVision()
2021-05-05 15:28:06 +03:00
// println(Solids.encodeToString(vision))
2021-03-01 19:10:15 +03:00
val smallBoxPrototype = vision.getPrototype("solids.smallBox".toName()) as? Box
assertNotNull(smallBoxPrototype)
assertEquals(30.0, smallBoxPrototype.xSize.toDouble())
2021-05-05 15:28:06 +03:00
val smallBoxVision = vision["composite-111.smallBox"]?.prototype as? Box
2021-03-01 19:10:15 +03:00
assertNotNull(smallBoxVision)
assertEquals(30.0, smallBoxVision.xSize.toDouble())
}
@Test
fun testGdmlExport() {
val xml = cubes.encodeToString()
//println(xml)
val gdml = Gdml.decodeFromString(xml)
val smallBox = gdml.getSolid<GdmlBox>("smallBox")
assertNotNull(smallBox)
assertEquals(30.0, smallBox.x.toDouble())
}
@Test
fun testCubesReSerialize() {
val vision = cubes.toVision()
val serialized = Solids.encodeToString(vision)
val deserialized = testContext.visionManager.decodeFromString(serialized) as SolidGroup
val smallBox = deserialized.getPrototype("solids.smallBox".toName()) as? Box
assertNotNull(smallBox)
assertEquals(30.0, smallBox.xSize.toDouble())
//println(testContext.visionManager.encodeToString(deserialized))
fun Vision.checkPrototypes() {
if (this is SolidReference) {
assertNotNull(this.prototype)
}
if (this is SolidGroup) {
children.forEach {
it.value.checkPrototypes()
}
}
}
deserialized.checkPrototypes()
}
}