-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Extract copy tests to ArithmeticTest file
- Loading branch information
Showing
2 changed files
with
128 additions
and
99 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
...-sdk/src/test/kotlin/org/eclipse/kuksa/vssSpecification/VssSpecificationArithmeticTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.eclipse.kuksa.vssSpecification | ||
|
||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.string.shouldStartWith | ||
import org.eclipse.kuksa.extension.vssProperty.div | ||
import org.eclipse.kuksa.extension.vssProperty.minus | ||
import org.eclipse.kuksa.extension.vssProperty.plus | ||
import org.eclipse.kuksa.extension.vssProperty.times | ||
import org.eclipse.kuksa.test.kotest.Unit | ||
|
||
class VssSpecificationArithmeticTest : BehaviorSpec({ | ||
tags(Unit) | ||
|
||
given("VssSpecification 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<Number>(5, 5L, 5f, 5.0) | ||
|
||
`when`("a plus operation is done") { | ||
val newValues = values.map { | ||
listOf( | ||
valueInt + it, | ||
valueFloat + it, | ||
valueLong + it, | ||
valueDouble + it, | ||
) | ||
} | ||
|
||
then("it should correctly add the values") { | ||
newValues.forEach { properties -> | ||
properties.forEach { | ||
it.value shouldBe 105 | ||
} | ||
} | ||
} | ||
} | ||
|
||
`when`("a minus operation is done") { | ||
val newValues = values.map { | ||
listOf( | ||
valueInt - it, | ||
valueFloat - it, | ||
valueLong - it, | ||
valueDouble - it, | ||
) | ||
} | ||
|
||
then("it should correctly subtract the values") { | ||
newValues.forEach { properties -> | ||
properties.forEach { | ||
it.value shouldBe 95 | ||
} | ||
} | ||
} | ||
} | ||
|
||
`when`("a divide operation with zero is done") { | ||
val exception = shouldThrow<ArithmeticException> { | ||
valueInt / 0 | ||
} | ||
|
||
then("it should throw an exception") { | ||
exception.message shouldStartWith "/ by zero" | ||
} | ||
} | ||
|
||
`when`("a divide operation is done") { | ||
val newValues = values.map { | ||
listOf( | ||
valueInt / it, | ||
valueFloat / it, | ||
valueLong / it, | ||
valueDouble / it, | ||
) | ||
} | ||
|
||
then("it should correctly divide the values") { | ||
newValues.forEach { properties -> | ||
properties.forEach { | ||
it.value shouldBe 20 | ||
} | ||
} | ||
} | ||
} | ||
|
||
`when`("a multiply operation is done") { | ||
val newValues = values.map { | ||
listOf( | ||
valueInt * it, | ||
valueFloat * it, | ||
valueLong * it, | ||
valueDouble * it, | ||
) | ||
} | ||
|
||
then("it should correctly multiply the values") { | ||
newValues.forEach { properties -> | ||
properties.forEach { | ||
it.value shouldBe 500 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters