From 242c5fec0bdfa9072ec8d19260c5134dc3e0a983 Mon Sep 17 00:00:00 2001 From: Benedikt Schwab Date: Mon, 11 Sep 2023 18:04:35 +0200 Subject: [PATCH] started replacing junit tests --- build.gradle.kts | 1 + buildSrc/src/main/kotlin/Dependencies.kt | 2 + .../io/rtron/math/transform/Affine2DTest.kt | 86 +++++++----------- .../io/rtron/math/transform/Affine3DTest.kt | 87 ++++++++----------- 4 files changed, 69 insertions(+), 107 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 2a9a3a63..588808ce 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -72,6 +72,7 @@ allprojects { testImplementation(Dependencies.junit) testImplementation(Dependencies.assertj) + testImplementation(Dependencies.kotest) testImplementation(Dependencies.mockk) } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index b75a3d7c..e2ee3181 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -24,6 +24,7 @@ object DependencyVersions { // testing libraries const val junit = "5.10.0" const val assertj = "3.24.2" + const val kotest = "5.7.1" const val mockk = "1.13.7" // logging libraries @@ -72,6 +73,7 @@ object Dependencies { // testing libraries const val junit = "org.junit.jupiter:junit-jupiter:${DependencyVersions.junit}" const val assertj = "org.assertj:assertj-core:${DependencyVersions.assertj}" + const val kotest = "io.kotest:kotest-runner-junit5:${DependencyVersions.kotest}" const val mockk = "io.mockk:mockk:${DependencyVersions.mockk}" // logging libraries diff --git a/rtron-math/src/test/kotlin/io/rtron/math/transform/Affine2DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/transform/Affine2DTest.kt index 78c03e96..19e9b772 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/transform/Affine2DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/transform/Affine2DTest.kt @@ -16,6 +16,8 @@ package io.rtron.math.transform +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe import io.rtron.math.geometry.euclidean.twod.Pose2D import io.rtron.math.geometry.euclidean.twod.Rotation2D import io.rtron.math.geometry.euclidean.twod.point.Vector2D @@ -23,47 +25,35 @@ import io.rtron.math.linear.RealMatrix import io.rtron.math.linear.RealVector import io.rtron.math.std.HALF_PI import io.rtron.math.std.QUARTER_PI -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Assertions.assertArrayEquals -import org.junit.jupiter.api.Nested -import org.junit.jupiter.api.Test -internal class Affine2DTest { +class Affine2DTest : FunSpec({ - @Nested - inner class TestTransform { - @Test - fun `test rotation`() { + context("TestTransform") { + test("test rotation") { val point = Vector2D.X_AXIS val rotationAngle = Rotation2D(HALF_PI) val affine = Affine2D.of(rotationAngle) val actualTransformed = affine.transform(point) - assertThat(actualTransformed).isEqualTo(Vector2D(0.0, 1.0)) + actualTransformed shouldBe Vector2D(0.0, 1.0) } } - @Nested - inner class TestInverseTransform { - - @Test - fun `inverse translation transform`() { + context("TestInverseTransform") { + test("inverse translation transform") { val point = Vector2D(10.0, 12.0) val translation = Vector2D(5.0, 2.0) val affine = Affine2D.of(translation) val actualTransformed = affine.inverseTransform(point) - assertThat(actualTransformed).isEqualTo(Vector2D(5.0, 10.0)) + actualTransformed shouldBe Vector2D(5.0, 10.0) } } - @Nested - inner class TestAffineMultiplication { - - @Test - fun `test appending`() { + context("TestAffineMultiplication") { + test("test appending") { val translation = Vector2D(1.0, 2.0) val affineA = Affine2D.of(translation) val scaling = RealVector.of(2.0, 3.0) @@ -78,16 +68,13 @@ internal class Affine2DTest { val actualAppended = affineA.append(affineB) val actualMatrix = actualAppended.toMatrix() - assertThat(actualMatrix.dimension).isEqualTo(expectedMatrix.dimension) - assertArrayEquals(expectedMatrix.toDoubleArray(), actualMatrix.toDoubleArray()) + actualMatrix.dimension shouldBe expectedMatrix.dimension + expectedMatrix.toDoubleArray() shouldBe actualMatrix.toDoubleArray() } } - @Nested - inner class TestPoseTransforms { - - @Test - fun `test translation`() { + context("TestPoseTransforms") { + test("test translation") { val point = Vector2D(5.0, 3.0) val pose = Pose2D(Vector2D(-10.0, -5.0), Rotation2D(0.0)) val affineTranslation = Affine2D.of(pose.point) @@ -96,78 +83,69 @@ internal class Affine2DTest { val actualTransformed = affine.transform(point) - assertThat(actualTransformed).isEqualTo(Vector2D(-5.0, -2.0)) + actualTransformed shouldBe Vector2D(-5.0, -2.0) } - @Test - fun `inverse transform with pose in origin`() { + test("inverse transform with pose in origin") { val point = Vector2D(5.0, 3.0) val pose = Pose2D(Vector2D(0.0, 0.0), Rotation2D(0.0)) val affine = Affine2D.of(Affine2D.of(pose.point), Affine2D.of(pose.rotation)) val actualTransformed = affine.inverseTransform(point) - assertThat(actualTransformed).isEqualTo(Vector2D(5.0, 3.0)) + actualTransformed shouldBe Vector2D(5.0, 3.0) } - @Test - fun `transform with rotated pose in origin`() { + test("transform with rotated pose in origin") { val point = Vector2D(5.0, 0.0) val pose = Pose2D(Vector2D(0.0, 0.0), Rotation2D(HALF_PI)) val affine = Affine2D.of(Affine2D.of(pose.point), Affine2D.of(pose.rotation)) val actualTransformed = affine.transform(point) - assertThat(actualTransformed).isEqualTo(Vector2D(0.0, 5.0)) + actualTransformed shouldBe Vector2D(0.0, 5.0) } - @Test - fun `transform with rotated pose and offset point`() { + test("transform with rotated pose and offset point") { val point = Vector2D(2.0, 3.0) val pose = Pose2D(Vector2D(0.0, 0.0), Rotation2D(HALF_PI)) val affine = Affine2D.of(Affine2D.of(pose.point), Affine2D.of(pose.rotation)) val actualTransformed = affine.transform(point) - assertThat(actualTransformed).isEqualTo(Vector2D(-3.0, 2.0)) + actualTransformed shouldBe Vector2D(-3.0, 2.0) } } - @Nested - inner class TestDecomposition { - - @Test - fun `extract translation point from basic affine`() { + context("TestDecomposition") { + test("extract translation point from basic affine") { val translation = Vector2D(1.0, 2.0) val affine = Affine2D.of(translation) val actual = affine.extractTranslation() - assertThat(actual).isEqualTo(translation) + actual shouldBe translation } - @Test - fun `extract rotation from basic affine`() { + test("extract rotation from basic affine") { val rotation = Rotation2D(QUARTER_PI) val affine = Affine2D.of(rotation) val actual = affine.extractRotation() - assertThat(actual).isEqualTo(rotation) + actual shouldBe rotation } - @Test - fun `extract scale vector from basic affine`() { + test("extract scale vector from basic affine") { val scaling = RealVector(doubleArrayOf(3.0, 2.0)) val affine = Affine2D.of(scaling) val actual = affine.extractScaling() - assertThat(actual).isEqualTo(scaling) + actual shouldBe scaling } - @Test - fun `extract rotation from affine with scaling, translation and rotation`() { + test("extract rotation from affine with scaling, translation and rotation") { val scaling = RealVector(doubleArrayOf(3.0, 2.0)) val translation = Vector2D(3.0, 2.0) val rotation = Rotation2D(HALF_PI) @@ -175,7 +153,7 @@ internal class Affine2DTest { val actual = affine.extractRotation() - assertThat(actual.toAngleRadians()).isEqualTo(rotation.toAngleRadians()) + actual.toAngleRadians() shouldBe rotation.toAngleRadians() } } -} +}) diff --git a/rtron-math/src/test/kotlin/io/rtron/math/transform/Affine3DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/transform/Affine3DTest.kt index aeefae24..c172d86b 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/transform/Affine3DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/transform/Affine3DTest.kt @@ -16,6 +16,8 @@ package io.rtron.math.transform +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe import io.rtron.math.geometry.euclidean.threed.Rotation3D import io.rtron.math.geometry.euclidean.threed.point.Vector3D import io.rtron.math.linear.RealMatrix @@ -25,42 +27,35 @@ import io.rtron.math.std.HALF_PI import org.assertj.core.api.Assertions.assertThat import org.assertj.core.data.Offset import org.junit.jupiter.api.Assertions.assertArrayEquals -import org.junit.jupiter.api.Nested -import org.junit.jupiter.api.Test import kotlin.math.cos import kotlin.math.sin import org.joml.Matrix4d as JOMLMatrix4d -internal class Affine3DTest { +class Affine3DTest : FunSpec({ - @Nested - inner class TestCreation { + context("TestCreation") { - @Test - fun `last entry must be 1 when creating a translation`() { + test("last entry must be 1 when creating a translation") { val translation = Vector3D(1.0, 2.0, 3.0) val affine = Affine3D.of(translation) val actual = affine.toRealMatrix()[3][3] - assertThat(actual).isEqualTo(1.0) + actual shouldBe 1.0 } } - @Nested - inner class TestDecomposition { + context("TestDecomposition") { - @Test - fun `test translation from 3x3 matrix`() { + test("test translation from 3x3 matrix") { val affine = Affine3D(JOMLMatrix4d()) val actual = affine.extractTranslation() - assertThat(actual).isEqualTo(Vector3D(0.0, 0.0, 0.0)) + actual shouldBe Vector3D(0.0, 0.0, 0.0) } - @Test - fun `test translation from 3x4 matrix`() { + test("test translation from 3x4 matrix") { val values = doubleArrayOf( 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 3.0, @@ -72,31 +67,28 @@ internal class Affine3DTest { val actual = affine.extractTranslation() - assertThat(actual).isEqualTo(Vector3D(0.0, 3.0, 2.0)) + actual shouldBe Vector3D(0.0, 3.0, 2.0) } - @Test - fun `test translation`() { + test("test translation") { val translation = Vector3D(1.0, 2.0, 3.0) val affine = Affine3D.of(translation) val actual = affine.extractTranslation() - assertThat(actual).isEqualTo(translation) + actual shouldBe translation } - @Test - fun `test scale`() { + test("test scale") { val scaling = RealVector(doubleArrayOf(3.0, 2.0, 1.0)) val affine = Affine3D.of(scaling) val actual = affine.extractScaling() - assertThat(actual).isEqualTo(scaling) + actual shouldBe scaling } - @Test - fun `test rotation`() { + test("test rotation") { val scaling = RealVector(doubleArrayOf(3.0, 2.0, 1.0)) val translation = Vector3D(3.0, 2.0, 1.0) val heading = HALF_PI @@ -114,16 +106,14 @@ internal class Affine3DTest { val actual = affine.extractRotationAffine().toRealMatrix() - assertThat(actual.dimension).isEqualTo(expectedRotationMatrix.dimension) + actual.dimension shouldBe expectedRotationMatrix.dimension assertArrayEquals(expectedRotationMatrix.toDoubleArray(), actual.toDoubleArray(), DBL_EPSILON) } } - @Nested - inner class TestAffineMultiplication { + context("TestAffineMultiplication") { - @Test - fun `test appending`() { + test("test appending") { val translation = Vector3D(1.0, 2.0, 3.0) val affineA = Affine3D.of(translation) val scaling = RealVector.of(2.0, 3.0, 4.0) @@ -139,40 +129,35 @@ internal class Affine3DTest { val actualAppended = affineA.append(affineB) val actualMatrix = actualAppended.toRealMatrix() - assertThat(actualMatrix.dimension).isEqualTo(expectedMatrix.dimension) - assertArrayEquals(expectedMatrix.toDoubleArray(), actualMatrix.toDoubleArray()) + actualMatrix.dimension shouldBe expectedMatrix.dimension + expectedMatrix.toDoubleArray() shouldBe actualMatrix.toDoubleArray() } } - @Nested - inner class TestTransforms { + context("TestTransforms") { - @Test - fun `test translation`() { + test("test translation") { val translation = Vector3D(1.0, 2.0, 3.0) val affine = Affine3D.of(translation) val actualTranslated = affine.transform(Vector3D.ZERO) - assertThat(actualTranslated).isEqualTo(translation) + actualTranslated shouldBe translation } - @Test - fun `test inverse translation`() { + test("test inverse translation") { val translation = Vector3D(1.0, 2.0, 3.0) val affine = Affine3D.of(translation) val actualTranslated = affine.inverseTransform(Vector3D.ZERO) - assertThat(actualTranslated).isEqualTo(-translation) + actualTranslated shouldBe -translation } } - @Nested - inner class TestRotations { + context("TestRotations") { - @Test - fun `test heading rotation`() { + test("test heading rotation") { val rotation = Rotation3D(HALF_PI, 0.0, 0.0) val affine = Affine3D.of(rotation) @@ -183,8 +168,7 @@ internal class Affine3DTest { assertThat(actualRotated.z).isCloseTo(0.0, Offset.offset(DBL_EPSILON)) } - @Test - fun `test pitch rotation`() { + test("test pitch rotation") { val rotation = Rotation3D(0.0, HALF_PI, 0.0) val affine = Affine3D.of(rotation) @@ -195,8 +179,7 @@ internal class Affine3DTest { assertThat(actualRotated.z).isCloseTo(-1.0, Offset.offset(DBL_EPSILON)) } - @Test - fun `test rotation based on new standard basis`() { + test("test rotation based on new standard basis") { val basisX = Vector3D(-1.0, 1.0, 0.0) val basisY = Vector3D(-1.0, 0.0, 1.0) val basisZ = Vector3D(1.0, 1.0, 1.0) @@ -211,11 +194,9 @@ internal class Affine3DTest { } } - @Nested - inner class TestConversions { + context("TestConversions") { - @Test - fun `test to double array`() { + test("test to double array") { val translation = Vector3D(1.0, 2.0, 3.0) val affine = Affine3D.of(translation) val expectedDoubleArray = doubleArrayOf( @@ -227,7 +208,7 @@ internal class Affine3DTest { val actualDoubleArray = affine.toDoubleArray() - assertArrayEquals(expectedDoubleArray, actualDoubleArray) + expectedDoubleArray shouldBe actualDoubleArray } } -} +})