From e43331aff968130baf1237e9cfd87385bcc70df2 Mon Sep 17 00:00:00 2001 From: Benedikt Schwab Date: Tue, 12 Sep 2023 07:38:18 +0200 Subject: [PATCH] replaced either assertions --- build.gradle.kts | 1 + buildSrc/src/main/kotlin/Dependencies.kt | 2 + .../analysis/function/LinearFunctionTest.kt | 3 +- .../threed/curve/LineString3DTest.kt | 23 +++---- .../euclidean/threed/solid/Cuboid3DTest.kt | 3 +- .../euclidean/threed/surface/Polygon3DTest.kt | 15 ++--- .../euclidean/twod/curve/Arc2DTest.kt | 65 +++++++------------ .../twod/curve/CompositeCurve2DTest.kt | 8 +-- .../euclidean/twod/curve/CubicCurve2DTest.kt | 30 ++++----- .../euclidean/twod/curve/LineSegment2DTest.kt | 35 ++++------ .../twod/curve/ParametricCubicCurve2DTest.kt | 33 ++++------ .../twod/curve/SpiralSegment2DTest.kt | 53 ++++++--------- .../range/DoubleRangeSetExtensionsTest.kt | 4 +- 13 files changed, 105 insertions(+), 170 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index a9604fe5..55c8128f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -71,6 +71,7 @@ allprojects { implementation(Dependencies.arrowOptics) testImplementation(Dependencies.kotest) + testImplementation(Dependencies.kotestExtensionArrow) testImplementation(Dependencies.assertj) testImplementation(Dependencies.mockk) } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 730021fe..05fd0a28 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -23,6 +23,7 @@ object DependencyVersions { // testing libraries const val kotest = "5.7.1" + const val kotestExtensionArrow = "1.3.3" const val assertj = "3.24.2" const val mockk = "1.13.7" @@ -71,6 +72,7 @@ object Dependencies { // testing libraries const val kotest = "io.kotest:kotest-runner-junit5:${DependencyVersions.kotest}" + const val kotestExtensionArrow = "io.kotest.extensions:kotest-assertions-arrow:${DependencyVersions.kotestExtensionArrow}" const val assertj = "org.assertj:assertj-core:${DependencyVersions.assertj}" const val mockk = "io.mockk:mockk:${DependencyVersions.mockk}" diff --git a/rtron-math/src/test/kotlin/io/rtron/math/analysis/function/LinearFunctionTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/analysis/function/LinearFunctionTest.kt index 839092aa..bd9b0344 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/analysis/function/LinearFunctionTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/analysis/function/LinearFunctionTest.kt @@ -19,6 +19,7 @@ package io.rtron.math.analysis.function import arrow.core.Either 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 @@ -42,7 +43,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() } } diff --git a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/curve/LineString3DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/curve/LineString3DTest.kt index 3c59f530..62cd81d2 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/curve/LineString3DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/curve/LineString3DTest.kt @@ -16,15 +16,14 @@ package io.rtron.math.geometry.euclidean.threed.curve -import arrow.core.Either import arrow.core.nonEmptyListOf +import io.kotest.assertions.arrow.core.shouldBeRight import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.doubles.plusOrMinus import io.kotest.matchers.shouldBe import io.rtron.math.geometry.curved.oned.point.CurveRelativeVector1D import io.rtron.math.geometry.euclidean.threed.point.Vector3D import io.rtron.math.std.DBL_EPSILON -import org.assertj.core.api.Assertions.assertThat class LineString3DTest : FunSpec({ context("TestLengthCalculation") { @@ -57,13 +56,11 @@ class LineString3DTest : FunSpec({ val pointB = Vector3D(0.0, 10.0, 0.0) val lineString = LineString3D(nonEmptyListOf(pointA, pointB), 0.0) - val actualReturn = lineString.calculatePointGlobalCS(CurveRelativeVector1D(5.0)) + val actualPoint = lineString.calculatePointGlobalCS(CurveRelativeVector1D(5.0)).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.x.shouldBe(0.0 plusOrMinus DBL_EPSILON) - actualReturn.value.y.shouldBe(5.0 plusOrMinus DBL_EPSILON) - actualReturn.value.z.shouldBe(0.0 plusOrMinus DBL_EPSILON) + actualPoint.x.shouldBe(0.0 plusOrMinus DBL_EPSILON) + actualPoint.y.shouldBe(5.0 plusOrMinus DBL_EPSILON) + actualPoint.z.shouldBe(0.0 plusOrMinus DBL_EPSILON) } test("line string with multiple points yields point on the top") { @@ -73,13 +70,11 @@ class LineString3DTest : FunSpec({ val pointD = Vector3D(0.0, 1.0, 0.0) val lineString = LineString3D(nonEmptyListOf(pointA, pointB, pointC, pointD), 0.0) - val actualReturn = lineString.calculatePointGlobalCS(CurveRelativeVector1D(2.5)) + val actualPoint = lineString.calculatePointGlobalCS(CurveRelativeVector1D(2.5)).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.x.shouldBe(0.5 plusOrMinus DBL_EPSILON) - actualReturn.value.y.shouldBe(1.0 plusOrMinus DBL_EPSILON) - actualReturn.value.z.shouldBe(0.0 plusOrMinus DBL_EPSILON) + actualPoint.x.shouldBe(0.5 plusOrMinus DBL_EPSILON) + actualPoint.y.shouldBe(1.0 plusOrMinus DBL_EPSILON) + actualPoint.z.shouldBe(0.0 plusOrMinus DBL_EPSILON) } } }) diff --git a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/solid/Cuboid3DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/solid/Cuboid3DTest.kt index 91461a76..21cda2b1 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/solid/Cuboid3DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/solid/Cuboid3DTest.kt @@ -17,6 +17,7 @@ package io.rtron.math.geometry.euclidean.threed.solid import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.collections.shouldHaveSize import io.rtron.math.geometry.euclidean.threed.point.Vector3D import io.rtron.math.geometry.euclidean.threed.surface.Polygon3D import org.assertj.core.api.Assertions.assertThat @@ -29,7 +30,7 @@ class Cuboid3DTest : FunSpec({ val actualPolygons = cuboid.calculatePolygonsGlobalCS() - assertThat(actualPolygons).hasSize(6) + actualPolygons shouldHaveSize 6 } test("generated polygons list contain base polygon") { diff --git a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/surface/Polygon3DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/surface/Polygon3DTest.kt index 2737e68e..8514e917 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/surface/Polygon3DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/threed/surface/Polygon3DTest.kt @@ -16,12 +16,11 @@ package io.rtron.math.geometry.euclidean.threed.surface -import arrow.core.Either import arrow.core.nonEmptyListOf +import io.kotest.assertions.arrow.core.shouldBeRight import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe import io.rtron.math.geometry.euclidean.threed.point.Vector3D -import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatIllegalArgumentException class Polygon3DTest : FunSpec({ @@ -82,11 +81,9 @@ class Polygon3DTest : FunSpec({ val pointC = Vector3D(2.0, 2.0, 1.0) val triangle = Polygon3D(nonEmptyListOf(pointA, pointB, pointC), 0.0) - val actualReturn = triangle.getNormal() + val actualNormal = triangle.getNormal().shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value shouldBe Vector3D.Z_AXIS + actualNormal shouldBe Vector3D.Z_AXIS } test("test planar quadrilateral polygon") { @@ -101,11 +98,9 @@ class Polygon3DTest : FunSpec({ ) val expectedResult = Vector3D(0.0, -1.0, 0.0) - val actualReturn = planarQuadrilateral.getNormal() + val actualNormal = planarQuadrilateral.getNormal().shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value shouldBe expectedResult + actualNormal shouldBe expectedResult } } }) diff --git a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/Arc2DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/Arc2DTest.kt index 8afe6fd1..d0af8060 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/Arc2DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/Arc2DTest.kt @@ -16,7 +16,7 @@ package io.rtron.math.geometry.euclidean.twod.curve -import arrow.core.Either +import io.kotest.assertions.arrow.core.shouldBeRight import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.doubles.plusOrMinus import io.kotest.matchers.shouldBe @@ -29,7 +29,6 @@ import io.rtron.math.std.PI import io.rtron.math.std.TWO_PI import io.rtron.math.transform.Affine2D import io.rtron.math.transform.AffineSequence2D -import org.assertj.core.api.Assertions.assertThat class Arc2DTest : FunSpec({ context("TestCenterCalculation") { @@ -86,43 +85,35 @@ class Arc2DTest : FunSpec({ test("calculate pose point on the start") { val arc = Arc2D(1.0, TWO_PI, 0.0, AffineSequence2D.EMPTY) - val actualReturn = arc.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO) + val actualPose = arc.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point shouldBe Vector2D.ZERO + actualPose.point shouldBe Vector2D.ZERO } test("calculate pose point on the curve") { val arc = Arc2D(1.0, TWO_PI, 0.0, AffineSequence2D.EMPTY) val curveRelativePoint = CurveRelativeVector1D(HALF_PI) - val actualReturn = arc.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = arc.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point shouldBe Vector2D(1.0, 1.0) + actualPose.point shouldBe Vector2D(1.0, 1.0) } test("calculate pose angle on the start") { val arc = Arc2D(1.0, TWO_PI, 0.0, AffineSequence2D.EMPTY) - val actualReturn = arc.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO) + val actualPose = arc.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.rotation.toAngleRadians() shouldBe 0.0 + actualPose.rotation.toAngleRadians() shouldBe 0.0 } test("calculate pose angle on the curve") { val arc = Arc2D(1.0, TWO_PI, 0.0, AffineSequence2D.EMPTY) val curveRelativePoint = CurveRelativeVector1D(HALF_PI) - val actualReturn = arc.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = arc.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.rotation.toAngleRadians() shouldBe HALF_PI + actualPose.rotation.toAngleRadians() shouldBe HALF_PI } } @@ -135,11 +126,9 @@ class Arc2DTest : FunSpec({ val affineSequence = AffineSequence2D.of(affine) val arc = Arc2D(1.0, TWO_PI, 0.0, affineSequence) - val actualReturn = arc.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO) + val actualPose = arc.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point shouldBe Vector2D(3.0, 5.0) + actualPose.point shouldBe Vector2D(3.0, 5.0) } test("calculate pose point on the curve") { @@ -150,11 +139,9 @@ class Arc2DTest : FunSpec({ val arc = Arc2D(1.0, TWO_PI, 0.0, affineSequence) val curveRelativePoint = CurveRelativeVector1D(HALF_PI) - val actualReturn = arc.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = arc.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point shouldBe Vector2D(2.0, 6.0) + actualPose.point shouldBe Vector2D(2.0, 6.0) } test("calculate pose in fourth quadrant") { @@ -164,12 +151,10 @@ class Arc2DTest : FunSpec({ val affineSequence = AffineSequence2D.of(affine) val arc = Arc2D(0.0125, 170.0, 0.0, affineSequence) - val actualReturn = arc.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO) + val actualPose = arc.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(point.x plusOrMinus DBL_EPSILON_4) - actualReturn.value.point.y.shouldBe(point.y plusOrMinus DBL_EPSILON_4) + actualPose.point.x.shouldBe(point.x plusOrMinus DBL_EPSILON_4) + actualPose.point.y.shouldBe(point.y plusOrMinus DBL_EPSILON_4) } test("calculate pose angle on the start") { @@ -179,11 +164,9 @@ class Arc2DTest : FunSpec({ val affineSequence = AffineSequence2D.of(affine) val arc = Arc2D(1.0, TWO_PI, 0.0, affineSequence) - val actualReturn = arc.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO) + val actualPose = arc.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - assertThat(actualReturn.value.rotation.toAngleRadians() shouldBe HALF_PI) + actualPose.rotation.toAngleRadians() shouldBe HALF_PI } test("calculate pose angle on the curve") { @@ -194,11 +177,9 @@ class Arc2DTest : FunSpec({ val arc = Arc2D(1.0, TWO_PI, 0.0, affineSequence) val curveRelativePoint = CurveRelativeVector1D(HALF_PI) - val actualReturn = arc.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = arc.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - assertThat(actualReturn.value.rotation.toAngleRadians() shouldBe PI) + actualPose.rotation.toAngleRadians() shouldBe PI } test("calculate pose angle in fourth quadrant") { @@ -209,11 +190,9 @@ class Arc2DTest : FunSpec({ val arc = Arc2D(1.0, TWO_PI, 0.0, affineSequence) val curveRelativePoint = CurveRelativeVector1D(PI) - val actualReturn = arc.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = arc.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - assertThat(actualReturn.value.rotation.toAngleRadians() shouldBe PI + HALF_PI) + actualPose.rotation.toAngleRadians() shouldBe PI + HALF_PI } } }) diff --git a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/CompositeCurve2DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/CompositeCurve2DTest.kt index dfdba318..7899d622 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/CompositeCurve2DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/CompositeCurve2DTest.kt @@ -16,7 +16,7 @@ package io.rtron.math.geometry.euclidean.twod.curve -import arrow.core.Either +import io.kotest.assertions.arrow.core.shouldBeRight import io.kotest.core.spec.style.FunSpec import io.rtron.math.analysis.function.univariate.pure.LinearFunction import io.rtron.math.geometry.curved.oned.point.CurveRelativeVector1D @@ -93,11 +93,9 @@ class CompositeCurve2DTest : FunSpec({ val compositeCurve = CompositeCurve2D(curveMembers, absoluteDomains, absoluteStarts.dropLast(1)) val curveRelativePoint = CurveRelativeVector1D(compositeCurve.length) - val actualPoint = compositeCurve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = compositeCurve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualPoint).isInstanceOf(Either.Right::class.java) - require(actualPoint is Either.Right) - assertThat(actualPoint.value.point).isNotEqualTo(Vector2D.ZERO) + assertThat(actualPose.point).isNotEqualTo(Vector2D.ZERO) } } }) diff --git a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/CubicCurve2DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/CubicCurve2DTest.kt index e57c65d2..98fc2937 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/CubicCurve2DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/CubicCurve2DTest.kt @@ -16,7 +16,7 @@ package io.rtron.math.geometry.euclidean.twod.curve -import arrow.core.Either +import io.kotest.assertions.arrow.core.shouldBeRight import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.doubles.plusOrMinus import io.kotest.matchers.shouldBe @@ -42,13 +42,11 @@ class CubicCurve2DTest : FunSpec({ val curve = CubicCurve2D(coefficients, 1.0, 0.0, affineSequence) val curveRelativePoint = CurveRelativeVector1D(1.0) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(1.0 plusOrMinus DBL_EPSILON) - actualReturn.value.point.y.shouldBe(1.0 plusOrMinus DBL_EPSILON) - actualReturn.value.rotation.angle.shouldBe(1.0 plusOrMinus DBL_EPSILON) + actualPose.point.x.shouldBe(1.0 plusOrMinus DBL_EPSILON) + actualPose.point.y.shouldBe(1.0 plusOrMinus DBL_EPSILON) + actualPose.rotation.angle.shouldBe(1.0 plusOrMinus DBL_EPSILON) } test("pose calculation of straight line with start pose offset") { @@ -59,12 +57,10 @@ class CubicCurve2DTest : FunSpec({ val curve = CubicCurve2D(coefficients, 1.0, 0.0, affineSequence) val curveRelativePoint = CurveRelativeVector1D(1.0) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(-1.0 plusOrMinus DBL_EPSILON) - actualReturn.value.point.y.shouldBe(1.0 plusOrMinus DBL_EPSILON) + actualPose.point.x.shouldBe(-1.0 plusOrMinus DBL_EPSILON) + actualPose.point.y.shouldBe(1.0 plusOrMinus DBL_EPSILON) } /** @@ -81,13 +77,11 @@ class CubicCurve2DTest : FunSpec({ val curve = CubicCurve2D(coefficients, length, 1E-4, affineSequence) val curveRelativePoint = CurveRelativeVector1D(length) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - assertThat(actualReturn.value.point.x).isNotCloseTo(-5.0558344684384622e+00, Offset.offset(DBL_EPSILON)) // not coincident with next curve element - assertThat(actualReturn.value.point.y).isNotCloseTo(9.6260358855640789e+00, Offset.offset(DBL_EPSILON)) // not coincident with next curve element - assertThat(actualReturn.value.rotation.angle).isNotCloseTo(3.8412114603351055e-01, Offset.offset(DBL_EPSILON)) // not coincident with next curve element + assertThat(actualPose.point.x).isNotCloseTo(-5.0558344684384622e+00, Offset.offset(DBL_EPSILON)) // not coincident with next curve element + assertThat(actualPose.point.y).isNotCloseTo(9.6260358855640789e+00, Offset.offset(DBL_EPSILON)) // not coincident with next curve element + assertThat(actualPose.rotation.angle).isNotCloseTo(3.8412114603351055e-01, Offset.offset(DBL_EPSILON)) // not coincident with next curve element } } }) diff --git a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/LineSegment2DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/LineSegment2DTest.kt index fb60cbab..feb89805 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/LineSegment2DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/LineSegment2DTest.kt @@ -16,7 +16,7 @@ package io.rtron.math.geometry.euclidean.twod.curve -import arrow.core.Either +import io.kotest.assertions.arrow.core.shouldBeRight import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.doubles.plusOrMinus import io.kotest.matchers.shouldBe @@ -25,7 +25,6 @@ import io.rtron.math.geometry.euclidean.twod.point.Vector2D import io.rtron.math.std.DBL_EPSILON import io.rtron.math.std.HALF_PI import io.rtron.math.std.QUARTER_PI -import org.assertj.core.api.Assertions.assertThat import kotlin.math.sqrt class LineSegment2DTest : FunSpec({ @@ -55,11 +54,9 @@ class LineSegment2DTest : FunSpec({ val pointB = Vector2D(0.0, 1.0) val lineSegment = LineSegment2D.of(pointA, pointB, 0.0) - val actualReturn = lineSegment.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO) + val actualPose = lineSegment.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.rotation.angle shouldBe HALF_PI + actualPose.rotation.angle shouldBe HALF_PI } test("angle of diagonal line segment") { @@ -67,11 +64,9 @@ class LineSegment2DTest : FunSpec({ val pointB = Vector2D(1.0, 1.0) val lineSegment = LineSegment2D.of(pointA, pointB, 0.0) - val actualReturn = lineSegment.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO) + val actualPose = lineSegment.calculatePoseGlobalCS(CurveRelativeVector1D.ZERO).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.rotation.angle shouldBe QUARTER_PI + actualPose.rotation.angle shouldBe QUARTER_PI } } @@ -83,11 +78,9 @@ class LineSegment2DTest : FunSpec({ val lineSegment = LineSegment2D.of(pointA, pointB, 0.0) val curveRelativePoint = CurveRelativeVector1D(5.0) - val actualReturn = lineSegment.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = lineSegment.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point shouldBe Vector2D(5.0, 0.0) + actualPose.point shouldBe Vector2D(5.0, 0.0) } test("point on diagonal line segment on axis") { @@ -96,12 +89,10 @@ class LineSegment2DTest : FunSpec({ val lineSegment = LineSegment2D.of(pointA, pointB, 0.0) val curveRelativePoint = CurveRelativeVector1D(sqrt(2.0)) - val actualReturn = lineSegment.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = lineSegment.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(1.0 plusOrMinus DBL_EPSILON) - actualReturn.value.point.y.shouldBe(1.0 plusOrMinus DBL_EPSILON) + actualPose.point.x.shouldBe(1.0 plusOrMinus DBL_EPSILON) + actualPose.point.y.shouldBe(1.0 plusOrMinus DBL_EPSILON) } test("point on diagonal line segment on axis 2") { @@ -110,11 +101,9 @@ class LineSegment2DTest : FunSpec({ val lineSegment = LineSegment2D.of(pointA, pointB, 0.0) val curveRelativePoint = CurveRelativeVector1D(1.0) - val actualReturn = lineSegment.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = lineSegment.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - assertThat(actualReturn.value.point shouldBe Vector2D(0.0, 0.0)) + actualPose.point shouldBe Vector2D(0.0, 0.0) } } }) diff --git a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/ParametricCubicCurve2DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/ParametricCubicCurve2DTest.kt index 5894d5d6..8d8d7a53 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/ParametricCubicCurve2DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/ParametricCubicCurve2DTest.kt @@ -16,7 +16,7 @@ package io.rtron.math.geometry.euclidean.twod.curve -import arrow.core.Either +import io.kotest.assertions.arrow.core.shouldBeRight import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.doubles.plusOrMinus import io.kotest.matchers.shouldBe @@ -29,7 +29,6 @@ import io.rtron.math.std.PI import io.rtron.math.std.QUARTER_PI import io.rtron.math.transform.Affine2D import io.rtron.math.transform.AffineSequence2D -import org.assertj.core.api.Assertions.assertThat import kotlin.math.sqrt class ParametricCubicCurve2DTest : FunSpec({ @@ -41,11 +40,9 @@ class ParametricCubicCurve2DTest : FunSpec({ val curve = ParametricCubicCurve2D(coefficientX, coefficientY, 10.0, 0.0) val curveRelativePoint = CurveRelativeVector1D(2.0) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point shouldBe Vector2D(2.0, 4.0) + actualPose.point shouldBe Vector2D(2.0, 4.0) } test("simple linear curve") { @@ -56,12 +53,10 @@ class ParametricCubicCurve2DTest : FunSpec({ val curve = ParametricCubicCurve2D(coefficientX, coefficientY, 10.0, 0.0, affineSequence) val curveRelativePoint = CurveRelativeVector1D(sqrt(2.0)) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(1.0 plusOrMinus DBL_EPSILON) - actualReturn.value.point.y.shouldBe(1.0 plusOrMinus DBL_EPSILON) + actualPose.point.x.shouldBe(1.0 plusOrMinus DBL_EPSILON) + actualPose.point.y.shouldBe(1.0 plusOrMinus DBL_EPSILON) } test("simple quadratic negative curve") { @@ -72,12 +67,10 @@ class ParametricCubicCurve2DTest : FunSpec({ val curve = ParametricCubicCurve2D(coefficientX, coefficientY, 10.0, 0.0, affineSequence) val curveRelativePoint = CurveRelativeVector1D(2.0) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(-2.0 plusOrMinus DBL_EPSILON_2) - actualReturn.value.point.y.shouldBe(-4.0 plusOrMinus DBL_EPSILON_2) + actualPose.point.x.shouldBe(-2.0 plusOrMinus DBL_EPSILON_2) + actualPose.point.y.shouldBe(-4.0 plusOrMinus DBL_EPSILON_2) } test("quadratic curve") { @@ -87,12 +80,10 @@ class ParametricCubicCurve2DTest : FunSpec({ val curveRelativePoint = CurveRelativeVector1D(length) val curve = ParametricCubicCurve2D(coefficientX, coefficientY, length, 0.0) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(length plusOrMinus DBL_EPSILON) - actualReturn.value.point.y.shouldBe(length * length plusOrMinus DBL_EPSILON) + actualPose.point.x.shouldBe(length plusOrMinus DBL_EPSILON) + actualPose.point.y.shouldBe(length * length plusOrMinus DBL_EPSILON) } } }) diff --git a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/SpiralSegment2DTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/SpiralSegment2DTest.kt index 2167e988..5d3bb540 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/SpiralSegment2DTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/geometry/euclidean/twod/curve/SpiralSegment2DTest.kt @@ -16,7 +16,7 @@ package io.rtron.math.geometry.euclidean.twod.curve -import arrow.core.Either +import io.kotest.assertions.arrow.core.shouldBeRight import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.doubles.plusOrMinus import io.kotest.matchers.shouldBe @@ -36,7 +36,6 @@ import io.rtron.math.transform.AffineSequence2D import mu.KotlinLogging import org.apache.commons.csv.CSVFormat import org.apache.commons.csv.CSVRecord -import org.assertj.core.api.Assertions.assertThat import java.io.FileReader import kotlin.io.path.Path import kotlin.io.path.absolute @@ -52,13 +51,11 @@ class SpiralSegment2DTest : FunSpec({ val curve = SpiralSegment2D(curvatureFunction, DBL_EPSILON_2, AffineSequence2D.of(affine)) val curveRelativePoint = CurveRelativeVector1D(1.3000000000000000e+02 - 1.0000000000000000e+02) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(6.5603727689096445e+01 plusOrMinus DBL_EPSILON_11) - actualReturn.value.point.y.shouldBe(9.8074617455403796e+00 plusOrMinus DBL_EPSILON_11) - actualReturn.value.rotation.angle.shouldBe( + actualPose.point.x.shouldBe(6.5603727689096445e+01 plusOrMinus DBL_EPSILON_11) + actualPose.point.y.shouldBe(9.8074617455403796e+00 plusOrMinus DBL_EPSILON_11) + actualPose.rotation.angle.shouldBe( 5.3186972285460032e-01 plusOrMinus DBL_EPSILON_4 ) @@ -71,13 +68,11 @@ class SpiralSegment2DTest : FunSpec({ val curve = SpiralSegment2D(curvatureFunction, DBL_EPSILON_2, AffineSequence2D.of(affine)) val curveRelativePoint = CurveRelativeVector1D(1.7999999146329435e+02 - 1.5999999146329435e+02) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(9.7828942354905308e+01 plusOrMinus DBL_EPSILON_11) - actualReturn.value.point.y.shouldBe(4.6971187858525226e+01 plusOrMinus DBL_EPSILON_11) - actualReturn.value.rotation.angle.shouldBe(1.1318693921172343e+00 plusOrMinus DBL_EPSILON_4) + actualPose.point.x.shouldBe(9.7828942354905308e+01 plusOrMinus DBL_EPSILON_11) + actualPose.point.y.shouldBe(4.6971187858525226e+01 plusOrMinus DBL_EPSILON_11) + actualPose.rotation.angle.shouldBe(1.1318693921172343e+00 plusOrMinus DBL_EPSILON_4) } test("first spiral of the example dataset CrossingComplex8Course") { @@ -87,13 +82,11 @@ class SpiralSegment2DTest : FunSpec({ val curve = SpiralSegment2D(curvatureFunction, DBL_EPSILON_2, AffineSequence2D.of(affine)) val curveRelativePoint = CurveRelativeVector1D(1.0507568316454000e+01 - 5.5455429999983039e+00) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(4.4963740167278593e+02 plusOrMinus DBL_EPSILON_6) - actualReturn.value.point.y.shouldBe(5.1577803259440122e+02 plusOrMinus DBL_EPSILON_6) - actualReturn.value.rotation.angle.shouldBe(4.4660983239227257e+00 plusOrMinus DBL_EPSILON_2) + actualPose.point.x.shouldBe(4.4963740167278593e+02 plusOrMinus DBL_EPSILON_6) + actualPose.point.y.shouldBe(5.1577803259440122e+02 plusOrMinus DBL_EPSILON_6) + actualPose.rotation.angle.shouldBe(4.4660983239227257e+00 plusOrMinus DBL_EPSILON_2) } test("second spiral of the example dataset CrossingComplex8Course") { @@ -103,13 +96,11 @@ class SpiralSegment2DTest : FunSpec({ val curve = SpiralSegment2D(curvatureFunction, DBL_EPSILON_2, AffineSequence2D.of(affine)) val curveRelativePoint = CurveRelativeVector1D(2.6019182043553606e+01 - 2.1057156727097912e+01) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(4.3763402923360974e+02 plusOrMinus DBL_EPSILON_6) - actualReturn.value.point.y.shouldBe(5.0819484814787387e+02 plusOrMinus DBL_EPSILON_6) - actualReturn.value.rotation.angle.shouldBe(3.1465437853028004e+00 plusOrMinus DBL_EPSILON_2) + actualPose.point.x.shouldBe(4.3763402923360974e+02 plusOrMinus DBL_EPSILON_6) + actualPose.point.y.shouldBe(5.0819484814787387e+02 plusOrMinus DBL_EPSILON_6) + actualPose.rotation.angle.shouldBe(3.1465437853028004e+00 plusOrMinus DBL_EPSILON_2) } } @@ -133,13 +124,11 @@ class SpiralSegment2DTest : FunSpec({ val curve = SpiralSegment2D(curvatureFunction, DBL_EPSILON_5, AffineSequence2D.of(affine)) val curveRelativePoint = CurveRelativeVector1D(record.get("s1").toDouble() - record.get("s0").toDouble()) - val actualReturn = curve.calculatePoseGlobalCS(curveRelativePoint) + val actualPose = curve.calculatePoseGlobalCS(curveRelativePoint).shouldBeRight() - assertThat(actualReturn).isInstanceOf(Either.Right::class.java) - require(actualReturn is Either.Right) - actualReturn.value.point.x.shouldBe(record.get("x1").toDouble() plusOrMinus DBL_EPSILON_8) - actualReturn.value.point.y.shouldBe(record.get("y1").toDouble() plusOrMinus DBL_EPSILON_8) - actualReturn.value.rotation.angle.shouldBe(Rotation2D(record.get("hdg1").toDouble()).angle plusOrMinus DBL_EPSILON_6) + actualPose.point.x.shouldBe(record.get("x1").toDouble() plusOrMinus DBL_EPSILON_8) + actualPose.point.y.shouldBe(record.get("y1").toDouble() plusOrMinus DBL_EPSILON_8) + actualPose.rotation.angle.shouldBe(Rotation2D(record.get("hdg1").toDouble()).angle plusOrMinus DBL_EPSILON_6) } } } diff --git a/rtron-math/src/test/kotlin/io/rtron/math/range/DoubleRangeSetExtensionsTest.kt b/rtron-math/src/test/kotlin/io/rtron/math/range/DoubleRangeSetExtensionsTest.kt index 29c7bf8f..a765cd2b 100644 --- a/rtron-math/src/test/kotlin/io/rtron/math/range/DoubleRangeSetExtensionsTest.kt +++ b/rtron-math/src/test/kotlin/io/rtron/math/range/DoubleRangeSetExtensionsTest.kt @@ -17,7 +17,7 @@ package io.rtron.math.range import io.kotest.core.spec.style.FunSpec -import org.assertj.core.api.Assertions.assertThat +import io.kotest.matchers.collections.shouldHaveSize import org.assertj.core.api.Assertions.assertThatIllegalArgumentException class DoubleRangeSetExtensionsTest : FunSpec({ @@ -38,7 +38,7 @@ class DoubleRangeSetExtensionsTest : FunSpec({ val actualRangeSet = RangeSet.ofNonIntersectingRanges(rangeA, rangeB) - assertThat(actualRangeSet.asRanges()).hasSize(1) + actualRangeSet.asRanges() shouldHaveSize 1 } } })