[orx-gradient] Move DescribeSpec based tests to jvmTest
This commit is contained in:
26
orx-gradient-descent/src/jvmTest/kotlin/TestDot.kt
Normal file
26
orx-gradient-descent/src/jvmTest/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)
|
||||
}
|
||||
})
|
||||
41
orx-gradient-descent/src/jvmTest/kotlin/TestGradient.kt
Normal file
41
orx-gradient-descent/src/jvmTest/kotlin/TestGradient.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import io.kotest.matchers.equals.shouldBeEqual
|
||||
import org.openrndr.extra.gradientdescent.gradient
|
||||
|
||||
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.shouldBeEqual(1)
|
||||
g0[0].shouldBeEqual(0.0)
|
||||
}
|
||||
it("its gradient at x=1 is ~2.0") {
|
||||
val g1 = gradient(doubleArrayOf(1.0), ::parabola)
|
||||
}
|
||||
it("its gradient at x=-1 is ~-2.0") {
|
||||
val g1 = gradient(doubleArrayOf(-1.0), ::parabola)
|
||||
}
|
||||
}
|
||||
|
||||
describe("a simple 2d function") {
|
||||
fun parabola(x: DoubleArray): Double {
|
||||
return x[0] * x[0] + x[1] * x[1]
|
||||
}
|
||||
|
||||
it("its gradient at x=0 is 0.0") {
|
||||
val g0 = gradient(doubleArrayOf(0.0, 0.0), ::parabola)
|
||||
g0.size.shouldBeEqual(2)
|
||||
g0[0].shouldBeEqual(0.0)
|
||||
}
|
||||
|
||||
it("its gradient at x=1 is ~2.0") {
|
||||
val g1 = gradient(doubleArrayOf(1.0, 1.0), ::parabola)
|
||||
}
|
||||
it("its gradient at x=-1 is ~-2.0") {
|
||||
val g1 = gradient(doubleArrayOf(-1.0, -1.0), ::parabola)
|
||||
}
|
||||
}
|
||||
})
|
||||
13
orx-gradient-descent/src/jvmTest/kotlin/TestMinimize.kt
Normal file
13
orx-gradient-descent/src/jvmTest/kotlin/TestMinimize.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
import io.kotest.core.spec.style.DescribeSpec
|
||||
import org.openrndr.extra.gradientdescent.minimize
|
||||
|
||||
class TestMinimize : DescribeSpec({
|
||||
describe("a simple 1d function") {
|
||||
fun parabola(x: DoubleArray): Double {
|
||||
return (x[0] + 1) * (x[0] + 1)
|
||||
}
|
||||
it("it can be minimized") {
|
||||
val result = minimize(doubleArrayOf(10.0), f = ::parabola)
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user