Skip to content

Commit

Permalink
replaced either assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Sep 12, 2023
1 parent 014fea7 commit e43331a
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 170 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ allprojects {
implementation(Dependencies.arrowOptics)

testImplementation(Dependencies.kotest)
testImplementation(Dependencies.kotestExtensionArrow)
testImplementation(Dependencies.assertj)
testImplementation(Dependencies.mockk)
}
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<IllegalArgumentException>()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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") {
Expand All @@ -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)
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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") {
Expand All @@ -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
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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") {
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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") {
Expand All @@ -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") {
Expand All @@ -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") {
Expand All @@ -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") {
Expand All @@ -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") {
Expand All @@ -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
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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") {
Expand All @@ -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)
}

/**
Expand All @@ -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
}
}
})
Loading

0 comments on commit e43331a

Please sign in to comment.