Skip to content

Commit

Permalink
started replacing junit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Sep 11, 2023
1 parent f1e708b commit 242c5fe
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 107 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ allprojects {

testImplementation(Dependencies.junit)
testImplementation(Dependencies.assertj)
testImplementation(Dependencies.kotest)
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 @@ -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
Expand Down Expand Up @@ -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
Expand Down
86 changes: 32 additions & 54 deletions rtron-math/src/test/kotlin/io/rtron/math/transform/Affine2DTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,44 @@

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
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)
Expand All @@ -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)
Expand All @@ -96,86 +83,77 @@ 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)
val affine = Affine2D.of(Affine2D.of(scaling), Affine2D.of(translation), Affine2D.of(rotation))

val actual = affine.extractRotation()

assertThat(actual.toAngleRadians()).isEqualTo(rotation.toAngleRadians())
actual.toAngleRadians() shouldBe rotation.toAngleRadians()
}
}
}
})
Loading

0 comments on commit 242c5fe

Please sign in to comment.