Remove Spek add Kotest
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
plugins {
|
||||
org.openrndr.extra.convention.`kotlin-multiplatform`
|
||||
alias(libs.plugins.kotest.multiplatform)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
testRuns["test"].executionTask {
|
||||
useJUnitPlatform {
|
||||
includeEngines("spek2")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation(project(":orx-parameters"))
|
||||
@@ -23,13 +23,17 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val commonTest by getting {
|
||||
dependencies {
|
||||
implementation(libs.kotest.assertions)
|
||||
implementation(libs.kotest.framework.engine)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val jvmTest by getting {
|
||||
dependencies {
|
||||
implementation(libs.kluent)
|
||||
implementation(libs.spek.dsl)
|
||||
runtimeOnly(libs.spek.junit5)
|
||||
implementation(libs.kotest.assertions)
|
||||
implementation(libs.kotest.framework.engine)
|
||||
runtimeOnly(libs.kotlin.reflect)
|
||||
}
|
||||
}
|
||||
|
||||
26
orx-gradient-descent/src/commonTest/kotlin/TestDot.kt
Normal file
26
orx-gradient-descent/src/commonTest/kotlin/TestDot.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import io.kotest.matchers.equals.shouldBeEqual
|
||||
import org.openrndr.extra.gradientdescent.dot
|
||||
|
||||
|
||||
class TestDot : DescribeSpec({
|
||||
describe("some vectors") {
|
||||
val a = doubleArrayOf(10.0)
|
||||
val b = doubleArrayOf(4.0)
|
||||
dot(a, b).shouldBeEqual(40.0)
|
||||
}
|
||||
|
||||
describe("a matrix and a vector") {
|
||||
val a = arrayOf(doubleArrayOf(10.0))
|
||||
val b = doubleArrayOf(1.0)
|
||||
val d = dot(a, b)
|
||||
d[0].shouldBeEqual(10.0)
|
||||
}
|
||||
|
||||
describe("another matrix and a vector") {
|
||||
val a = arrayOf(doubleArrayOf(1.0))
|
||||
val b = doubleArrayOf(19.99999999995339)
|
||||
val d = dot(a, b)
|
||||
d[0].shouldBeEqual(19.99999999995339)
|
||||
}
|
||||
})
|
||||
@@ -1,18 +1,16 @@
|
||||
import org.amshove.kluent.`should be equal to`
|
||||
import org.amshove.kluent.`should equal`
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import io.kotest.matchers.equals.shouldBeEqual
|
||||
import org.openrndr.extra.gradientdescent.gradient
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
object TestGradient : Spek({
|
||||
class TestGradient : DescribeSpec({
|
||||
describe("a simple 1d function") {
|
||||
fun parabola(x: DoubleArray): Double {
|
||||
return x[0] * x[0]
|
||||
}
|
||||
it("its gradient at x=0 is 0.0") {
|
||||
val g0 = gradient(doubleArrayOf(0.0), ::parabola)
|
||||
g0.size `should equal` 1
|
||||
g0[0] `should be equal to` 0.0
|
||||
g0.size.shouldBeEqual(1)
|
||||
g0[0].shouldBeEqual(0.0)
|
||||
}
|
||||
it("its gradient at x=1 is ~2.0") {
|
||||
val g1 = gradient(doubleArrayOf(1.0), ::parabola)
|
||||
@@ -29,8 +27,8 @@ object TestGradient : Spek({
|
||||
|
||||
it("its gradient at x=0 is 0.0") {
|
||||
val g0 = gradient(doubleArrayOf(0.0, 0.0), ::parabola)
|
||||
g0.size `should equal` 2
|
||||
g0[0] `should be equal to` 0.0
|
||||
g0.size.shouldBeEqual(2)
|
||||
g0[0].shouldBeEqual(0.0)
|
||||
}
|
||||
|
||||
it("its gradient at x=1 is ~2.0") {
|
||||
@@ -1,11 +1,10 @@
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import org.openrndr.extra.gradientdescent.minimize
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
object TestMinimize : Spek({
|
||||
class TestMinimize : DescribeSpec({
|
||||
describe("a simple 1d function") {
|
||||
fun parabola(x: DoubleArray): Double {
|
||||
return (x[0]+1) * (x[0]+1)
|
||||
return (x[0] + 1) * (x[0] + 1)
|
||||
}
|
||||
it("it can be minimized") {
|
||||
val result = minimize(doubleArrayOf(10.0), f = ::parabola)
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.openrndr.extra.gradientdescent
|
||||
import org.amshove.kluent.`should be equal to`
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
object TestDot : Spek({
|
||||
describe("some vectors") {
|
||||
val a = doubleArrayOf(10.0)
|
||||
val b = doubleArrayOf(4.0)
|
||||
|
||||
dot(a,b) `should be equal to` 40.0
|
||||
|
||||
}
|
||||
describe("a matrix and a vector") {
|
||||
val a = arrayOf(doubleArrayOf(10.0))
|
||||
val b = doubleArrayOf(1.0)
|
||||
val d = dot(a,b)
|
||||
d[0] `should be equal to` 10.0
|
||||
}
|
||||
|
||||
describe("a matrix and a vector") {
|
||||
val a = arrayOf(doubleArrayOf(1.0))
|
||||
val b = doubleArrayOf(19.99999999995339)
|
||||
val d = dot(a,b)
|
||||
d[0] `should be equal to` 19.99999999995339
|
||||
}
|
||||
|
||||
})
|
||||
@@ -1,10 +1,10 @@
|
||||
import org.amshove.kluent.shouldBeNear
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import io.kotest.matchers.doubles.plusOrMinus
|
||||
import io.kotest.matchers.shouldBe
|
||||
import org.openrndr.extra.gradientdescent.minimizeModel
|
||||
import org.openrndr.math.Vector2
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
object TestMinimizeModel : Spek({
|
||||
class TestMinimizeModel : DescribeSpec({
|
||||
describe("a model") {
|
||||
val m = object {
|
||||
var x = 0.0
|
||||
@@ -14,8 +14,8 @@ object TestMinimizeModel : Spek({
|
||||
minimizeModel(m) { m->
|
||||
(m.x - 4.0) * (m.x - 4.0) + (m.y - 3.0) * (m.y - 3.0)
|
||||
}
|
||||
m.x.shouldBeNear(4.0, 0.01)
|
||||
m.y.shouldBeNear(3.0, 0.01)
|
||||
m.x.shouldBe(4.0.plusOrMinus(0.01))
|
||||
m.y.shouldBe(3.0.plusOrMinus(0.01))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ object TestMinimizeModel : Spek({
|
||||
minimizeModel(m) { m->
|
||||
(m.position.x - 4.0) * (m.position.x - 4.0) + (m.position.y - 3.0) * (m.position.y - 3.0)
|
||||
}
|
||||
m.position.x.shouldBeNear(4.0, 0.01)
|
||||
m.position.y.shouldBeNear(3.0, 0.01)
|
||||
m.position.x.shouldBe(4.0.plusOrMinus(0.01))
|
||||
m.position.y.shouldBe(3.0.plusOrMinus(0.01))
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user