Skip to content

Commit

Permalink
test: Add VssSpecification tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrylo committed Oct 20, 2023
1 parent 37e70c7 commit 9400913
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,27 @@ class VssSpecificationTest : BehaviorSpec({
`when`("finding the whole heritage") {
val heritage = vssVehicle.heritage
then("it should return all possible heirs") {
heritage shouldBe listOf(vssVehicle.driver, vssVehicle.body, vssVehicle.driver.heartRate)
heritage shouldBe listOf(
vssVehicle.driver,
vssVehicle.passenger,
vssVehicle.body,
vssVehicle.driver.heartRate,
vssVehicle.passenger.heartRate,
)
}
}
`when`("finding a heritage line") {
val heritageLine = vssVehicle.findHeritageLine(VssHeartRate())
val heritageLine = vssVehicle.findHeritageLine(VssDriver.VssHeartRate())
then("it should return the correct line") {
heritageLine shouldBe listOf(vssVehicle.driver, vssVehicle.driver.heartRate)
}
}
`when`("finding specific properties") {
val properties = vssVehicle.findProperties(VssDriver.VssHeartRate::class)
then("it should return all VssProperties which fit the class") {
properties.size shouldBe 2
}
}
`when`("getting the variable name") {
val variableName = vssVehicle.variableName
then("it should be correct") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import kotlin.reflect.KClass

data class VssVehicle(
val driver: VssDriver = VssDriver(),
val passenger: VssPassenger = VssPassenger(),
val body: VssBody = VssBody(),
override val uuid: String = "Vehicle",
override val vssPath: String = "Vehicle",
Expand All @@ -33,7 +34,7 @@ data class VssVehicle(
override val comment: String = "",
) : VssSpecification {
override val children: Set<VssSpecification>
get() = setOf(driver, body)
get() = setOf(driver, passenger, body)
}

data class VssBody(
Expand All @@ -59,16 +60,42 @@ data class VssDriver(
get() = setOf(heartRate)
override val parentClass: KClass<*>
get() = VssVehicle::class

data class VssHeartRate(
override val uuid: String = "Driver HeartRate",
override val vssPath: String = "Vehicle.Driver.HeartRate",
override val description: String = "Heart rate of the driver.",
override val type: String = "sensor",
override val comment: String = "",
override val value: Int = 100,
) : VssProperty<Int> {
override val parentClass: KClass<*>
get() = VssDriver::class
}
}

data class VssHeartRate(
override val uuid: String = "HeartRate",
override val vssPath: String = "Vehicle.Driver.HeartRate",
override val description: String = "Heart rate of the driver.",
override val type: String = "sensor",
data class VssPassenger(
val heartRate: VssHeartRate = VssHeartRate(),
override val uuid: String = "Passenger",
override val vssPath: String = "Vehicle.Passenger",
override val description: String = "Passenger data",
override val type: String = "branch",
override val comment: String = "",
override val value: Int = 100,
) : VssProperty<Int> {
) : VssSpecification {
override val children: Set<VssSpecification>
get() = setOf(heartRate)
override val parentClass: KClass<*>
get() = VssDriver::class
get() = VssVehicle::class

data class VssHeartRate(
override val uuid: String = "Passenger HeartRate",
override val vssPath: String = "Vehicle.Passenger.HeartRate",
override val description: String = "Heart rate of the Passenger.",
override val type: String = "sensor",
override val comment: String = "",
override val value: Int = 80,
) : VssProperty<Int> {
override val parentClass: KClass<*>
get() = VssPassenger::class
}
}

0 comments on commit 9400913

Please sign in to comment.