Skip to content

Commit

Permalink
replaced assertions with kotest
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Sep 13, 2023
1 parent c6a27b3 commit 8bee5c0
Show file tree
Hide file tree
Showing 43 changed files with 398 additions and 458 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ allprojects {
implementation(Dependencies.arrowOptics)

testImplementation(Dependencies.kotest)
testImplementation(Dependencies.assertj)
testImplementation(Dependencies.kotestExtensionArrow)
testImplementation(Dependencies.mockk)
}

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object DependencyVersions {

// testing libraries
const val kotest = "5.7.1"
const val assertj = "3.24.2"
const val kotestExtensionArrow = "1.3.3"
const val mockk = "1.13.7"

// logging libraries
Expand Down Expand Up @@ -71,7 +71,7 @@ object Dependencies {

// testing libraries
const val kotest = "io.kotest:kotest-runner-junit5:${DependencyVersions.kotest}"
const val assertj = "org.assertj:assertj-core:${DependencyVersions.assertj}"
const val kotestExtensionArrow = "io.kotest.extensions:kotest-assertions-arrow:${DependencyVersions.kotestExtensionArrow}"
const val mockk = "io.mockk:mockk:${DependencyVersions.mockk}"

// logging libraries
Expand Down
20 changes: 10 additions & 10 deletions rtron-math/src/test/kotlin/io/rtron/math/analysis/FresnelTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package io.rtron.math.analysis

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.doubles.plusOrMinus
import io.kotest.matchers.shouldBe
import io.rtron.math.std.DBL_EPSILON
import mu.KotlinLogging
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVRecord
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.data.Offset
import java.io.FileReader
import kotlin.io.path.Path
import kotlin.io.path.absolute
Expand Down Expand Up @@ -51,30 +51,30 @@ class FresnelTest : FunSpec({

val (actualX, actualY) = Fresnel.calculatePoint(l)

assertThat(actualX).isCloseTo(x, Offset.offset(DBL_EPSILON))
assertThat(actualY).isCloseTo(y, Offset.offset(DBL_EPSILON))
actualX.shouldBe(x plusOrMinus DBL_EPSILON)
actualY.shouldBe(y plusOrMinus DBL_EPSILON)
}
}

test("test against sample value 1") {
val (actualX, actualY) = Fresnel.calculatePoint(-4.2284028867950161)

assertThat(actualX).isCloseTo(-0.51547336206019945, Offset.offset(DBL_EPSILON))
assertThat(actualY).isCloseTo(-0.5736113070569262, Offset.offset(DBL_EPSILON))
actualX.shouldBe(-0.51547336206019945 plusOrMinus DBL_EPSILON)
actualY.shouldBe(-0.5736113070569262 plusOrMinus DBL_EPSILON)
}

test("test against sample value 2") {
val (actualX, actualY) = Fresnel.calculatePoint(883.12677767970729)

assertThat(actualX).isCloseTo(0.50035646758310326, Offset.offset(DBL_EPSILON))
assertThat(actualY).isCloseTo(0.49994666781760994, Offset.offset(DBL_EPSILON))
actualX.shouldBe(0.50035646758310326 plusOrMinus DBL_EPSILON)
actualY.shouldBe(0.49994666781760994 plusOrMinus DBL_EPSILON)
}

test("test against sample value 3") {
val (actualX, actualY) = Fresnel.calculatePoint(-1.8154077322757265)

assertThat(actualX).isCloseTo(-0.33992314562581244, Offset.offset(DBL_EPSILON))
assertThat(actualY).isCloseTo(-0.43687889962705617, Offset.offset(DBL_EPSILON))
actualX.shouldBe(-0.33992314562581244 plusOrMinus DBL_EPSILON)
actualY.shouldBe(-0.43687889962705617 plusOrMinus DBL_EPSILON)
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package io.rtron.math.analysis.function

import arrow.core.Either
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeInstanceOf
import io.rtron.math.analysis.function.univariate.pure.LinearFunction
import io.rtron.math.range.Range
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatIllegalArgumentException

class LinearFunctionTest : FunSpec({
context("TestValueCalculation") {
Expand All @@ -32,7 +33,7 @@ class LinearFunctionTest : FunSpec({
val actualResult = linearFunction.value(3.0)

require(actualResult is Either.Right)
assertThat(actualResult.value).isEqualTo(40.0)
actualResult.value shouldBe 40.0
}

test("out of range value evaluation throws an IllegalArgumentException") {
Expand All @@ -41,7 +42,7 @@ class LinearFunctionTest : FunSpec({
val actualResult = linearFunction.value(3.0)

require(actualResult is Either.Left)
assertThat(actualResult.value).isInstanceOf(IllegalArgumentException::class.java)
actualResult.value.shouldBeInstanceOf<IllegalArgumentException>()
}
}

Expand All @@ -56,14 +57,16 @@ class LinearFunctionTest : FunSpec({

val actualLinearFunction = LinearFunction.ofInclusivePoints(3.0, 2.0, 7.0, -4.0)

assertThat(actualLinearFunction).isEqualTo(expectedLinearFunction)
actualLinearFunction shouldBe expectedLinearFunction
}

test("creation of linear function with two equal points throws an IllegalArgumentException") {
val x = 2.1
val y = 3.4

assertThatIllegalArgumentException().isThrownBy { LinearFunction.ofInclusivePoints(x, y, x, y) }
shouldThrow<IllegalArgumentException> {
LinearFunction.ofInclusivePoints(x, y, x, y)
}
}
}

Expand All @@ -78,7 +81,7 @@ class LinearFunctionTest : FunSpec({

val actualLinearFunction = LinearFunction.ofInclusiveYValuesAndUnitSlope(2.0, 4.0)

assertThat(actualLinearFunction).isEqualTo(expectedLinearFunction)
actualLinearFunction shouldBe expectedLinearFunction
}

test("with negative unit slope") {
Expand All @@ -90,7 +93,7 @@ class LinearFunctionTest : FunSpec({

val actualLinearFunction = LinearFunction.ofInclusiveYValuesAndUnitSlope(17.0, 14.0)

assertThat(actualLinearFunction).isEqualTo(expectedLinearFunction)
actualLinearFunction shouldBe expectedLinearFunction
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package io.rtron.math.analysis.function.bivariate

import arrow.core.Either
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.rtron.math.analysis.function.bivariate.combination.SectionedBivariateFunction
import io.rtron.math.analysis.function.bivariate.pure.PlaneFunction
import io.rtron.math.range.Range
import org.assertj.core.api.Assertions.assertThat

class SectionedBivariateFunctionTest : FunSpec({
context("TestCreation") {
Expand All @@ -33,7 +33,7 @@ class SectionedBivariateFunctionTest : FunSpec({
val actualResult = sectionedPlane.value(0.0, 0.0)

require(actualResult is Either.Right)
assertThat(actualResult.value).isEqualTo(1.0)
actualResult.value shouldBe 1.0
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package io.rtron.math.analysis.function.univariate.combination
import arrow.core.Either
import arrow.core.nonEmptyListOf
import io.kotest.core.spec.style.FunSpec
import org.assertj.core.api.Assertions.assertThat
import io.kotest.matchers.shouldBe

class ConcatenatedFunctionTest : FunSpec({

Expand All @@ -37,11 +37,11 @@ class ConcatenatedFunctionTest : FunSpec({

require(actualResult1 is Either.Left)
require(actualResult2 is Either.Right)
assertThat(actualResult2.value).isEqualTo(0.0)
actualResult2.value shouldBe 0.0
require(actualResult3 is Either.Right)
assertThat(actualResult3.value).isEqualTo(-5.0)
actualResult3.value shouldBe -5.0
require(actualResult4 is Either.Right)
assertThat(actualResult4.value).isEqualTo(-5.0)
actualResult4.value shouldBe -5.0
}

test("concatenated function with absolute start at -2") {
Expand All @@ -56,11 +56,11 @@ class ConcatenatedFunctionTest : FunSpec({

require(actualResult1 is Either.Left)
require(actualResult2 is Either.Right)
assertThat(actualResult2.value).isEqualTo(0.0)
actualResult2.value shouldBe 0.0
require(actualResult3 is Either.Right)
assertThat(actualResult3.value).isEqualTo(-5.0)
actualResult3.value shouldBe -5.0
require(actualResult4 is Either.Right)
assertThat(actualResult4.value).isEqualTo(-5.0)
actualResult4.value shouldBe -5.0
}

test("concatenated function with absolute start at 2") {
Expand All @@ -75,11 +75,11 @@ class ConcatenatedFunctionTest : FunSpec({

require(actualResult1 is Either.Left)
require(actualResult2 is Either.Right)
assertThat(actualResult2.value).isEqualTo(0.0)
actualResult2.value shouldBe 0.0
require(actualResult3 is Either.Right)
assertThat(actualResult3.value).isEqualTo(-5.0)
actualResult3.value shouldBe -5.0
require(actualResult4 is Either.Right)
assertThat(actualResult4.value).isEqualTo(-5.0)
actualResult4.value shouldBe -5.0
}
}

Expand All @@ -100,13 +100,13 @@ class ConcatenatedFunctionTest : FunSpec({
val actualResult4 = concatenatedFunction.valueInFuzzy(7.0, 1E-7)

require(actualResult1 is Either.Right)
assertThat(actualResult1.value).isEqualTo(2.0)
actualResult1.value shouldBe 2.0
require(actualResult2 is Either.Right)
assertThat(actualResult2.value).isEqualTo(32.0)
actualResult2.value shouldBe 32.0
require(actualResult3 is Either.Right)
assertThat(actualResult3.value).isEqualTo(1.0)
actualResult3.value shouldBe 1.0
require(actualResult4 is Either.Right)
assertThat(actualResult4.value).isEqualTo(49.0)
actualResult4.value shouldBe 49.0
}

test("concatenated function with absolute start at -2") {
Expand All @@ -124,13 +124,13 @@ class ConcatenatedFunctionTest : FunSpec({
val actualResult4 = concatenatedFunction.valueInFuzzy(5.0, 1E-7)

require(actualResult1 is Either.Right)
assertThat(actualResult1.value).isEqualTo(2.0)
actualResult1.value shouldBe 2.0
require(actualResult2 is Either.Right)
assertThat(actualResult2.value).isEqualTo(32.0)
actualResult2.value shouldBe 32.0
require(actualResult3 is Either.Right)
assertThat(actualResult3.value).isEqualTo(1.0)
actualResult3.value shouldBe 1.0
require(actualResult4 is Either.Right)
assertThat(actualResult4.value).isEqualTo(49.0)
actualResult4.value shouldBe 49.0
}

test("concatenated function with absolute start at 2") {
Expand All @@ -148,13 +148,13 @@ class ConcatenatedFunctionTest : FunSpec({
val actualResult4 = concatenatedFunction.valueInFuzzy(9.0, 1E-7)

require(actualResult1 is Either.Right)
assertThat(actualResult1.value).isEqualTo(2.0)
actualResult1.value shouldBe 2.0
require(actualResult2 is Either.Right)
assertThat(actualResult2.value).isEqualTo(32.0)
actualResult2.value shouldBe 32.0
require(actualResult3 is Either.Right)
assertThat(actualResult3.value).isEqualTo(1.0)
actualResult3.value shouldBe 1.0
require(actualResult4 is Either.Right)
assertThat(actualResult4.value).isEqualTo(49.0)
actualResult4.value shouldBe 49.0
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,69 +17,69 @@
package io.rtron.math.geometry.euclidean.threed

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.doubles.plusOrMinus
import io.kotest.matchers.shouldBe
import io.rtron.math.std.DBL_EPSILON
import io.rtron.math.std.DBL_EPSILON_3
import io.rtron.math.std.HALF_PI
import io.rtron.math.std.QUARTER_PI
import io.rtron.math.std.TWO_PI
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.data.Offset

class Rotation3DTest : FunSpec({
context("TestAngleAssignments") {

test("heading assignment with half pi") {
val actualHeading = Rotation3D(HALF_PI, 0.0, 0.0).heading

assertThat(actualHeading).isCloseTo(HALF_PI, Offset.offset(DBL_EPSILON))
actualHeading.shouldBe(HALF_PI plusOrMinus DBL_EPSILON)
}

test("heading assignment with two pi") {
val actualHeading = Rotation3D(TWO_PI, 0.0, 0.0).heading

assertThat(actualHeading).isCloseTo(0.0, Offset.offset(DBL_EPSILON_3))
actualHeading.shouldBe(0.0 plusOrMinus DBL_EPSILON_3)
}

test("heading assignment with two and a half pi") {
val actualHeading = Rotation3D(HALF_PI + TWO_PI, 0.0, 0.0).heading

assertThat(actualHeading).isCloseTo(HALF_PI, Offset.offset(DBL_EPSILON_3))
actualHeading.shouldBe(HALF_PI plusOrMinus DBL_EPSILON_3)
}

test("pitch assignment with quarter pi") {
val actualPitch = Rotation3D(0.0, QUARTER_PI, 0.0).pitch

assertThat(actualPitch).isCloseTo(QUARTER_PI, Offset.offset(DBL_EPSILON))
actualPitch.shouldBe(QUARTER_PI plusOrMinus DBL_EPSILON)
}

test("pitch assignment with two pi") {
val actualPitch = Rotation3D(0.0, TWO_PI, 0.0).pitch

assertThat(actualPitch).isCloseTo(0.0, Offset.offset(DBL_EPSILON_3))
actualPitch.shouldBe(0.0 plusOrMinus DBL_EPSILON_3)
}

test("pitch assignment with two and a half pi") {
val actualPitch = Rotation3D(0.0, QUARTER_PI + TWO_PI, 0.0).pitch

assertThat(actualPitch).isCloseTo(QUARTER_PI, Offset.offset(DBL_EPSILON_3))
actualPitch.shouldBe(QUARTER_PI plusOrMinus DBL_EPSILON_3)
}

test("roll assignment with quarter pi") {
val actualRoll = Rotation3D(0.0, 0.0, HALF_PI).roll

assertThat(actualRoll).isCloseTo(HALF_PI, Offset.offset(DBL_EPSILON))
actualRoll.shouldBe(HALF_PI plusOrMinus DBL_EPSILON)
}

test("roll assignment with two pi") {
val actualRoll = Rotation3D(0.0, 0.0, TWO_PI).roll

assertThat(actualRoll).isCloseTo(0.0, Offset.offset(DBL_EPSILON_3))
actualRoll.shouldBe(0.0 plusOrMinus DBL_EPSILON_3)
}

test("roll assignment with two and a half pi") {
val actualRoll = Rotation3D(0.0, 0.0, HALF_PI + TWO_PI).roll

assertThat(actualRoll).isCloseTo(HALF_PI, Offset.offset(DBL_EPSILON_3))
actualRoll.shouldBe(HALF_PI plusOrMinus DBL_EPSILON_3)
}
}
})
Loading

0 comments on commit 8bee5c0

Please sign in to comment.