From 3d774bf577a102c7cf2cbe46c40819e18d66a965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Hu=CC=88sers?= Date: Wed, 1 Nov 2023 16:47:03 +0100 Subject: [PATCH] test: Add tests for Long / Float / Double for VssProperties --- .../VssSpecificationCopyTest.kt | 75 ++++++++++++++++--- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssSpecificationCopyTest.kt b/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssSpecificationCopyTest.kt index 7b7e02e6..d38877ca 100644 --- a/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssSpecificationCopyTest.kt +++ b/kuksa-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssSpecificationCopyTest.kt @@ -67,44 +67,95 @@ class VssSpecificationCopyTest : BehaviorSpec({ } and("values for arithmetic operations") { + val valueInt = VssValueInt(value = 100) + val valueFloat = VssValueFloat(value = 100f) + val valueLong = VssValueLong(value = 100L) + val valueDouble = VssValueDouble(value = 100.0) + val values = listOf(5, 5L, 5f, 5.0) `when`("a plus operation is done") { - val newValues = values.map { driverHeartRate + it } + val newValues = values.map { + listOf( + valueInt + it, + valueFloat + it, + valueLong + it, + valueDouble + it, + ) + } then("it should correctly add the values") { - newValues.forEach { - it.value shouldBe 105 + newValues.forEach { properties -> + properties.forEach { + it.value shouldBe 105 + } } } } `when`("a minus operation is done") { - val newValues = values.map { driverHeartRate - it } + val newValues = values.map { + listOf( + valueInt - it, + valueFloat - it, + valueLong - it, + valueDouble - it, + ) + } then("it should correctly subtract the values") { - newValues.forEach { - it.value shouldBe 95 + newValues.forEach { properties -> + properties.forEach { + it.value shouldBe 95 + } } } } + `when`("a divide operation with zero is done") { + val exception = shouldThrow { + valueInt / 0 + } + + then("it should throw an exception") { + exception.message shouldStartWith "/ by zero" + } + } + `when`("a divide operation is done") { - val newValues = values.map { driverHeartRate / it } + val newValues = values.map { + listOf( + valueInt / it, + valueFloat / it, + valueLong / it, + valueDouble / it, + ) + } then("it should correctly divide the values") { - newValues.forEach { - it.value shouldBe 20 + newValues.forEach { properties -> + properties.forEach { + it.value shouldBe 20 + } } } } `when`("a multiply operation is done") { - val newValues = values.map { driverHeartRate * it } + val newValues = values.map { + listOf( + valueInt * it, + valueFloat * it, + valueLong * it, + valueDouble * it, + ) + } then("it should correctly multiply the values") { - newValues.forEach { - it.value shouldBe 500 + newValues.forEach { properties -> + properties.forEach { + it.value shouldBe 500 + } } } }