Skip to content

Commit

Permalink
replaced junit with kotest
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Sep 11, 2023
1 parent f1e708b commit c6a27b3
Show file tree
Hide file tree
Showing 49 changed files with 652 additions and 1,114 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ allprojects {
implementation(Dependencies.arrowCore)
implementation(Dependencies.arrowOptics)

testImplementation(Dependencies.junit)
testImplementation(Dependencies.kotest)
testImplementation(Dependencies.assertj)
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 @@ -22,7 +22,7 @@ object DependencyVersions {
const val arrow = "1.2.1"

// testing libraries
const val junit = "5.10.0"
const val kotest = "5.7.1"
const val assertj = "3.24.2"
const val mockk = "1.13.7"

Expand Down Expand Up @@ -70,7 +70,7 @@ object Dependencies {
const val arrowOpticsKspPlugin = "io.arrow-kt:arrow-optics-ksp-plugin:${DependencyVersions.arrow}"

// testing libraries
const val junit = "org.junit.jupiter:junit-jupiter:${DependencyVersions.junit}"
const val kotest = "io.kotest:kotest-runner-junit5:${DependencyVersions.kotest}"
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 @@ -27,12 +27,10 @@ import io.rtron.math.range.Range
import io.rtron.math.range.arrange
import io.rtron.math.std.PI
import io.rtron.math.transform.AffineSequence2D
import org.junit.jupiter.api.Test
import kotlin.io.path.Path

object SpiralSegment2DWriterTest {

@Test
fun writeSpiralSegment2DToCsvFile() {
val path = Path("out/test_files/SpiralSegment2D/SpiralSegment2D-line.csv")
val header = listOf("curvePosition", "x", "y")
Expand Down
26 changes: 10 additions & 16 deletions rtron-math/src/test/kotlin/io/rtron/math/analysis/FresnelTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,29 @@

package io.rtron.math.analysis

import io.kotest.core.spec.style.FunSpec
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 org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import java.io.FileReader
import kotlin.io.path.Path
import kotlin.io.path.absolute
import kotlin.io.path.exists

class FresnelTest {
class FresnelTest : FunSpec({

private val logger = KotlinLogging.logger {}
val logger = KotlinLogging.logger {}

@Nested
inner class TestDatasetCalculation {
context("TestDatasetCalculation") {

@Test
fun `test against csv sample dataset`() {
test("test against csv sample dataset") {
val filePath = Path("src/test/cpp/spiral/build/sampled_fresnel_integral.csv").absolute()
if (!filePath.exists()) {
logger.warn { "Dataset does not exist at $filePath, skipping test" }
return
return@test
}
val fileReader = FileReader(filePath.toFile())

Expand All @@ -59,28 +56,25 @@ class FresnelTest {
}
}

@Test
fun `test against sample value 1`() {
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))
}

@Test
fun `test against sample value 2`() {
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))
}

@Test
fun `test against sample value 3`() {
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))
}
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@
package io.rtron.math.analysis.function

import arrow.core.Either
import io.kotest.core.spec.style.FunSpec
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
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test

internal class LinearFunctionTest {
class LinearFunctionTest : FunSpec({
context("TestValueCalculation") {

@Nested
inner class TestValueCalculation {

@Test
fun `f(3)=5 times x plus 25 should be 40`() {
test("f(3)=5 times x plus 25 should be 40") {
val linearFunction = LinearFunction(5.0, 25.0)

val actualResult = linearFunction.value(3.0)
Expand All @@ -39,8 +35,7 @@ internal class LinearFunctionTest {
assertThat(actualResult.value).isEqualTo(40.0)
}

@Test
fun `out of range value evaluation throws an IllegalArgumentException`() {
test("out of range value evaluation throws an IllegalArgumentException") {
val linearFunction = LinearFunction(-5.0, 25.0, Range.closedOpen(1.0, 3.0))

val actualResult = linearFunction.value(3.0)
Expand All @@ -50,11 +45,9 @@ internal class LinearFunctionTest {
}
}

@Nested
inner class TestFactoryMethodOfInclusivePoints {
context("TestFactoryMethodOfInclusivePoints") {

@Test
fun `basic creation of linear function with two points`() {
test("basic creation of linear function with two points") {
val expectedLinearFunction = LinearFunction(
-3.0 / 2.0,
13.0 / 2.0,
Expand All @@ -66,20 +59,17 @@ internal class LinearFunctionTest {
assertThat(actualLinearFunction).isEqualTo(expectedLinearFunction)
}

@Test
fun `creation of linear function with two equal points throws an IllegalArgumentException`() {
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) }
}
}

@Nested
inner class TestFactoryMethodOfInclusiveYValueAndUnitSlope {
context("TestFactoryMethodOfInclusiveYValueAndUnitSlope") {

@Test
fun `with positive unit slope`() {
test("with positive unit slope") {
val expectedLinearFunction = LinearFunction(
1.0,
2.0,
Expand All @@ -91,8 +81,7 @@ internal class LinearFunctionTest {
assertThat(actualLinearFunction).isEqualTo(expectedLinearFunction)
}

@Test
fun `with negative unit slope`() {
test("with negative unit slope") {
val expectedLinearFunction = LinearFunction(
-1.0,
17.0,
Expand All @@ -104,4 +93,4 @@ internal class LinearFunctionTest {
assertThat(actualLinearFunction).isEqualTo(expectedLinearFunction)
}
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@
package io.rtron.math.analysis.function.bivariate

import arrow.core.Either
import io.kotest.core.spec.style.FunSpec
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
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test

internal class SectionedBivariateFunctionTest {
class SectionedBivariateFunctionTest : FunSpec({
context("TestCreation") {

@Nested
inner class TestCreation {

@Test
fun `shifting with bivariate function of complete range should not throw an error`() {
test("shifting with bivariate function of complete range should not throw an error") {
val planeFunction = PlaneFunction(1.0, 1.0, 0.0, Range.all(), Range.all())
val sectionedPlane = SectionedBivariateFunction(planeFunction, Range.closed(1.0, 3.0), Range.all())

Expand All @@ -40,4 +36,4 @@ internal class SectionedBivariateFunctionTest {
assertThat(actualResult.value).isEqualTo(1.0)
}
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ 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 org.junit.jupiter.api.Test

internal class ConcatenatedFunctionTest {
class ConcatenatedFunctionTest : FunSpec({

class TestCreationOfLinearFunctions {
context("TestCreationOfLinearFunctions") {

@Test
fun `concatenated function with absolute start at 0`() {
test("concatenated function with absolute start at 0") {
val starts = listOf(0.0, 5.0)
val intercepts = listOf(0.0, -5.0)
val concatenatedFunction = ConcatenatedFunction.ofLinearFunctions(starts, intercepts)
Expand All @@ -45,8 +44,7 @@ internal class ConcatenatedFunctionTest {
assertThat(actualResult4.value).isEqualTo(-5.0)
}

@Test
fun `concatenated function with absolute start at -2`() {
test("concatenated function with absolute start at -2") {
val starts = listOf(-2.0, 3.0)
val intercepts = listOf(0.0, -5.0)
val concatenatedFunction = ConcatenatedFunction.ofLinearFunctions(starts, intercepts)
Expand All @@ -65,8 +63,7 @@ internal class ConcatenatedFunctionTest {
assertThat(actualResult4.value).isEqualTo(-5.0)
}

@Test
fun `concatenated function with absolute start at 2`() {
test("concatenated function with absolute start at 2") {
val starts = listOf(2.0, 7.0)
val intercepts = listOf(0.0, -5.0)
val concatenatedFunction = ConcatenatedFunction.ofLinearFunctions(starts, intercepts)
Expand All @@ -86,10 +83,9 @@ internal class ConcatenatedFunctionTest {
}
}

class TestCreationOfPolynomialFunctions {
context("TestCreationOfPolynomialFunctions") {

@Test
fun `concatenated function with absolute start at 0`() {
test("concatenated function with absolute start at 0") {
val starts = nonEmptyListOf(0.0, 5.0)
val coefficients = nonEmptyListOf(
doubleArrayOf(2.0, 3.0, 4.0, 1.0),
Expand All @@ -113,8 +109,7 @@ internal class ConcatenatedFunctionTest {
assertThat(actualResult4.value).isEqualTo(49.0)
}

@Test
fun `concatenated function with absolute start at -2`() {
test("concatenated function with absolute start at -2") {
val starts = nonEmptyListOf(-2.0, 3.0)
val coefficients = nonEmptyListOf(
doubleArrayOf(2.0, 3.0, 4.0, 1.0),
Expand All @@ -138,8 +133,7 @@ internal class ConcatenatedFunctionTest {
assertThat(actualResult4.value).isEqualTo(49.0)
}

@Test
fun `concatenated function with absolute start at 2`() {
test("concatenated function with absolute start at 2") {
val starts = nonEmptyListOf(2.0, 7.0)
val coefficients = nonEmptyListOf(
doubleArrayOf(2.0, 3.0, 4.0, 1.0),
Expand All @@ -163,4 +157,4 @@ internal class ConcatenatedFunctionTest {
assertThat(actualResult4.value).isEqualTo(49.0)
}
}
}
})
Loading

0 comments on commit c6a27b3

Please sign in to comment.