Replace kluent with kotlin.test (#361)
This commit is contained in:
@@ -12,7 +12,6 @@ dokka = "1.7.10"
|
|||||||
nebulaRelease = "18.0.7"
|
nebulaRelease = "18.0.7"
|
||||||
gradleNexusPublish = "2.0.0"
|
gradleNexusPublish = "2.0.0"
|
||||||
boofcv = "1.2.2"
|
boofcv = "1.2.2"
|
||||||
kluent = "1.73"
|
|
||||||
junitJupiter = "5.12.2"
|
junitJupiter = "5.12.2"
|
||||||
slf4j = "2.0.17"
|
slf4j = "2.0.17"
|
||||||
libfreenect = "0.5.7-1.5.9"
|
libfreenect = "0.5.7-1.5.9"
|
||||||
@@ -84,7 +83,6 @@ jsoup = { group = "org.jsoup", name = "jsoup", version.ref = "jsoup" }
|
|||||||
|
|
||||||
jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junitJupiter" }
|
jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junitJupiter" }
|
||||||
jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junitJupiter" }
|
jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junitJupiter" }
|
||||||
kluent = { group = "org.amshove.kluent", name = "kluent", version.ref = "kluent" }
|
|
||||||
slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }
|
slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class TestSpectral {
|
|||||||
|
|
||||||
for (c in colors) {
|
for (c in colors) {
|
||||||
val r = linearToReflectance(c)
|
val r = linearToReflectance(c)
|
||||||
assertEquals(r.size, 38)
|
assertEquals(38, r.size)
|
||||||
val xyz = reflectanceToXYZ(r)
|
val xyz = reflectanceToXYZ(r)
|
||||||
val cp = xyz.toRGBa().matchLinearity(c)
|
val cp = xyz.toRGBa().matchLinearity(c)
|
||||||
assertTrue(cp.toVector4().distanceTo(c.toVector4()) < 5E-3)
|
assertTrue(cp.toVector4().distanceTo(c.toVector4()) < 5E-3)
|
||||||
|
|||||||
@@ -20,10 +20,5 @@ kotlin {
|
|||||||
implementation(project(":orx-jvm:orx-gui"))
|
implementation(project(":orx-jvm:orx-gui"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jvmTest by getting {
|
|
||||||
dependencies {
|
|
||||||
implementation(libs.kluent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package typed
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.openrndr.extra.expressions.typed.evaluateTypedExpression
|
import org.openrndr.extra.expressions.typed.evaluateTypedExpression
|
||||||
import org.openrndr.math.Vector2
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package typed
|
|||||||
import org.openrndr.extra.expressions.typed.compileFunction1OrNull
|
import org.openrndr.extra.expressions.typed.compileFunction1OrNull
|
||||||
import org.openrndr.extra.noise.uniform
|
import org.openrndr.extra.noise.uniform
|
||||||
import org.openrndr.math.Vector2
|
import org.openrndr.math.Vector2
|
||||||
|
import kotlin.math.cos
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@@ -111,7 +112,6 @@ class TestTypedCompiledExpression {
|
|||||||
|
|
||||||
val c3 = compileFunction1OrNull<Map<String, Any>, Double>("cos(2.0)", "x", constants = env)!!
|
val c3 = compileFunction1OrNull<Map<String, Any>, Double>("cos(2.0)", "x", constants = env)!!
|
||||||
val r3 = c3(emptyMap())
|
val r3 = c3(emptyMap())
|
||||||
|
assertEquals(cos(2.0), r3, 1E-6)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,11 +47,6 @@ kotlin {
|
|||||||
implementation(project(":orx-jvm:orx-gui"))
|
implementation(project(":orx-jvm:orx-gui"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jvmTest by getting {
|
|
||||||
dependencies {
|
|
||||||
implementation(libs.kluent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,32 @@
|
|||||||
import org.amshove.kluent.invoking
|
|
||||||
import org.amshove.kluent.`should throw`
|
|
||||||
import org.amshove.kluent.shouldBeEqualTo
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.assertThrows
|
||||||
import org.openrndr.extra.expressions.ExpressionException
|
import org.openrndr.extra.expressions.ExpressionException
|
||||||
import org.openrndr.extra.expressions.compileExpression
|
import org.openrndr.extra.expressions.compileExpression
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class TestCompiledExpression {
|
class TestCompiledExpression {
|
||||||
@Test
|
@Test
|
||||||
fun `a simple compiled expression`() {
|
fun `a simple compiled expression`() {
|
||||||
val expression = "someValue"
|
val expression = "someValue"
|
||||||
val function = compileExpression(expression, constants = mutableMapOf("someValue" to 5.0))
|
val function = compileExpression(expression, constants = mutableMapOf("someValue" to 5.0))
|
||||||
function().shouldBeEqualTo(5.0)
|
assertEquals(5.0, function())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a compiled expression with updated context`() {
|
fun `a compiled expression with updated context`() {
|
||||||
val expression = "someValue"
|
val expression = "someValue"
|
||||||
val context = mutableMapOf("someValue" to 5.0)
|
val context = mutableMapOf("someValue" to 5.0)
|
||||||
val function = compileExpression(expression, constants = context)
|
val function = compileExpression(expression, constants = context)
|
||||||
function().shouldBeEqualTo(5.0)
|
assertEquals(5.0, function())
|
||||||
context["someValue"] = 6.0
|
context["someValue"] = 6.0
|
||||||
function().shouldBeEqualTo(6.0)
|
assertEquals(6.0, function())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `an erroneous compiled expression`() {
|
fun `an erroneous compiled expression`() {
|
||||||
val expression = "1bork"
|
val expression = "1bork"
|
||||||
invoking {
|
assertThrows<ExpressionException> {
|
||||||
compileExpression(expression, constants = mutableMapOf("someValue" to 5.0))
|
compileExpression(expression, constants = mutableMapOf("someValue" to 5.0))
|
||||||
} `should throw` ExpressionException::class
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,29 +1,29 @@
|
|||||||
import org.amshove.kluent.invoking
|
|
||||||
import org.amshove.kluent.`should throw`
|
|
||||||
import org.amshove.kluent.shouldBeEqualTo
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.openrndr.extra.expressions.*
|
import org.openrndr.extra.expressions.compileFunction1
|
||||||
|
import org.openrndr.extra.expressions.compileFunction2
|
||||||
|
import org.openrndr.extra.expressions.compileFunction3
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class TestCompiledFunctions {
|
class TestCompiledFunctions {
|
||||||
@Test
|
@Test
|
||||||
fun `a simple compiled function1`() {
|
fun `a simple compiled function1`() {
|
||||||
val expression = "t"
|
val expression = "t"
|
||||||
val function = compileFunction1(expression, "t")
|
val function = compileFunction1(expression, "t")
|
||||||
function(-5.0).shouldBeEqualTo(-5.0)
|
assertEquals(-5.0, function(-5.0))
|
||||||
function(5.0).shouldBeEqualTo(5.0)
|
assertEquals(5.0, function(5.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a simple compiled function2`() {
|
fun `a simple compiled function2`() {
|
||||||
val expression = "x + y"
|
val expression = "x + y"
|
||||||
val function = compileFunction2(expression, "x", "y")
|
val function = compileFunction2(expression, "x", "y")
|
||||||
function(1.0, 2.0).shouldBeEqualTo(3.0)
|
assertEquals(3.0, function(1.0, 2.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a simple compiled function3`() {
|
fun `a simple compiled function3`() {
|
||||||
val expression = "x + y + z"
|
val expression = "x + y + z"
|
||||||
val function = compileFunction3(expression, "x", "y", "z")
|
val function = compileFunction3(expression, "x", "y", "z")
|
||||||
function(1.0, 2.0, 3.0).shouldBeEqualTo(6.0)
|
assertEquals(6.0, function(1.0, 2.0, 3.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import org.amshove.kluent.shouldBeEqualTo
|
|
||||||
import org.openrndr.extra.expressions.watchingExpression1
|
import org.openrndr.extra.expressions.watchingExpression1
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class TestExpressionDelegates {
|
class TestExpressionDelegates {
|
||||||
|
|
||||||
@@ -10,7 +10,6 @@ class TestExpressionDelegates {
|
|||||||
var expression = "x * x"
|
var expression = "x * x"
|
||||||
val function1 by watchingExpression1(::expression, "x")
|
val function1 by watchingExpression1(::expression, "x")
|
||||||
}
|
}
|
||||||
state.function1(5.0).shouldBeEqualTo(25.0)
|
assertEquals(25.0, state.function1(5.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,45 +1,51 @@
|
|||||||
import org.amshove.kluent.`should throw`
|
import org.junit.jupiter.api.assertThrows
|
||||||
import org.amshove.kluent.`with message`
|
|
||||||
import org.amshove.kluent.invoking
|
|
||||||
import org.openrndr.extra.expressions.ExpressionException
|
import org.openrndr.extra.expressions.ExpressionException
|
||||||
import org.openrndr.extra.expressions.evaluateExpression
|
import org.openrndr.extra.expressions.evaluateExpression
|
||||||
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class TestExpressionErrors {
|
class TestExpressionErrors {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `an expression with non-sensible writing`() {
|
fun `an expression with non-sensible writing`() {
|
||||||
val expression = ")("
|
val expression = ")("
|
||||||
invoking {
|
assertThrows<ExpressionException> {
|
||||||
evaluateExpression(expression)
|
evaluateExpression(expression)
|
||||||
} `should throw` ExpressionException::class
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `an expression trying to reassign a number`() {
|
fun `an expression trying to reassign a number`() {
|
||||||
val expression = "3 = 5"
|
val expression = "3 = 5"
|
||||||
invoking {
|
assertThrows<ExpressionException> {
|
||||||
evaluateExpression(expression)
|
evaluateExpression(expression)
|
||||||
} `should throw` ExpressionException::class
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `an expression that uses non-existing functions`() {
|
fun `an expression that uses non-existing functions`() {
|
||||||
val expression = "notExisting(5)"
|
val expression = "notExisting(5)"
|
||||||
invoking {
|
val exception = assertFailsWith<ExpressionException> {
|
||||||
evaluateExpression(expression)
|
evaluateExpression(expression)
|
||||||
} `should throw` ExpressionException::class `with message` "error in evaluation of 'notExisting(5)': unresolved function: 'notExisting(x0)'"
|
}
|
||||||
|
assertEquals(
|
||||||
|
"error in evaluation of 'notExisting(5)': unresolved function: 'notExisting(x0)'",
|
||||||
|
exception.message
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `an expression that uses non-existing variables`() {
|
fun `an expression that uses non-existing variables`() {
|
||||||
val expression = "notExisting + 4"
|
val expression = "notExisting + 4"
|
||||||
invoking {
|
val exception = assertFailsWith<ExpressionException> {
|
||||||
evaluateExpression(expression)
|
evaluateExpression(expression)
|
||||||
} `should throw` ExpressionException::class `with message` "error in evaluation of 'notExisting+4': unresolved value: 'notExisting'. available values: {}"
|
}
|
||||||
|
assertEquals(
|
||||||
|
"error in evaluation of 'notExisting+4': unresolved value: 'notExisting'. available values: {}",
|
||||||
|
exception.message
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
import org.amshove.kluent.shouldBeEqualTo
|
|
||||||
import org.amshove.kluent.shouldBeNear
|
|
||||||
import org.openrndr.extra.expressions.FunctionExtensions
|
import org.openrndr.extra.expressions.FunctionExtensions
|
||||||
import org.openrndr.extra.expressions.evaluateExpression
|
import org.openrndr.extra.expressions.evaluateExpression
|
||||||
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertNotNull
|
||||||
|
|
||||||
class TestExpressions {
|
class TestExpressions {
|
||||||
@Test
|
@Test
|
||||||
fun `a value reference`() {
|
fun `a value reference`() {
|
||||||
val expression = "someValue"
|
val expression = "someValue"
|
||||||
val result = evaluateExpression(expression, constants= mapOf("someValue" to 5.0))
|
val result = evaluateExpression(expression, constants = mapOf("someValue" to 5.0))
|
||||||
result?.shouldBeEqualTo(5.0)
|
assertEquals(5.0, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a backticked value reference`() {
|
fun `a backticked value reference`() {
|
||||||
val expression = "`some-value`"
|
val expression = "`some-value`"
|
||||||
val result = evaluateExpression(expression, constants= mapOf("some-value" to 5.0))
|
val result = evaluateExpression(expression, constants = mapOf("some-value" to 5.0))
|
||||||
result?.shouldBeEqualTo(5.0)
|
assertEquals(5.0, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -24,111 +25,174 @@ class TestExpressions {
|
|||||||
fun `a function call`() {
|
fun `a function call`() {
|
||||||
val expression = "sqrt(4.0)"
|
val expression = "sqrt(4.0)"
|
||||||
val result = evaluateExpression(expression)
|
val result = evaluateExpression(expression)
|
||||||
result?.shouldBeNear(2.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(2.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a function call with the name in backticks`() {
|
fun `a function call with the name in backticks`() {
|
||||||
val expression = "`sqrt`(4.0)"
|
val expression = "`sqrt`(4.0)"
|
||||||
val result = evaluateExpression(expression)
|
val result = evaluateExpression(expression)
|
||||||
result?.shouldBeNear(2.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(2.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `two function calls`() {
|
fun `two function calls`() {
|
||||||
val expression = "sqrt(4.0) * sqrt(4.0)"
|
val expression = "sqrt(4.0) * sqrt(4.0)"
|
||||||
val result = evaluateExpression(expression)
|
val result = evaluateExpression(expression)
|
||||||
result?.shouldBeNear(4.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(4.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `two argument max function call`() {
|
fun `two argument max function call`() {
|
||||||
val expression = "max(0.0, 4.0)"
|
val expression = "max(0.0, 4.0)"
|
||||||
val result = evaluateExpression(expression)
|
val result = evaluateExpression(expression)
|
||||||
result?.shouldBeNear(4.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(4.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `two argument min function call`() {
|
fun `two argument min function call`() {
|
||||||
val expression = "min(8.0, 4.0)"
|
val expression = "min(8.0, 4.0)"
|
||||||
val result = evaluateExpression(expression)
|
val result = evaluateExpression(expression)
|
||||||
result?.shouldBeNear(4.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(4.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `three argument function call`() {
|
fun `three argument function call`() {
|
||||||
val expression = "mix(8.0, 4.0, 0.5)"
|
val expression = "mix(8.0, 4.0, 0.5)"
|
||||||
val result = evaluateExpression(expression)
|
val result = evaluateExpression(expression)
|
||||||
result?.shouldBeNear(6.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(6.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `five argument function call`() {
|
fun `five argument function call`() {
|
||||||
val expression = "map(0.0, 1.0, 0.0, 8.0, 0.5)"
|
val expression = "map(0.0, 1.0, 0.0, 8.0, 0.5)"
|
||||||
val result = evaluateExpression(expression)
|
val result = evaluateExpression(expression)
|
||||||
result?.shouldBeNear(4.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(4.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `two argument function call, where argument order matters`() {
|
fun `two argument function call, where argument order matters`() {
|
||||||
val expression = "pow(2.0, 3.0)"
|
val expression = "pow(2.0, 3.0)"
|
||||||
val result = evaluateExpression(expression)
|
val result = evaluateExpression(expression)
|
||||||
result?.shouldBeNear(8.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(8.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `nested function call`() {
|
fun `nested function call`() {
|
||||||
val expression = "sqrt(min(8.0, 4.0))"
|
val expression = "sqrt(min(8.0, 4.0))"
|
||||||
val result = evaluateExpression(expression)
|
val result = evaluateExpression(expression)
|
||||||
result?.shouldBeNear(2.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(2.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `extension function0 call`() {
|
fun `extension function0 call`() {
|
||||||
val expression = "extension()"
|
val expression = "extension()"
|
||||||
val result = evaluateExpression(expression, functions = FunctionExtensions(functions0 = mapOf("extension" to { 2.0 })))
|
val result = evaluateExpression(
|
||||||
result?.shouldBeNear(2.0, 10E-6)
|
expression,
|
||||||
|
functions = FunctionExtensions(
|
||||||
|
functions0 = mapOf("extension" to { 2.0 })
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertNotNull(result)
|
||||||
|
assertEquals(2.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `extension function1 call`(){
|
fun `extension function1 call`() {
|
||||||
val expression = "extension(1.0)"
|
val expression = "extension(1.0)"
|
||||||
val result = evaluateExpression(expression, functions = FunctionExtensions(functions1 = mapOf("extension" to { x -> x * 2.0 })))
|
val result = evaluateExpression(
|
||||||
result?.shouldBeNear(2.0, 10E-6)
|
expression,
|
||||||
|
functions = FunctionExtensions(
|
||||||
|
functions1 = mapOf("extension" to { x ->
|
||||||
|
x * 2.0
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertNotNull(result)
|
||||||
|
assertEquals(2.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `extension function1 call with dashed name in backticks`(){
|
fun `extension function1 call with dashed name in backticks`() {
|
||||||
val expression = "`extension-function`(1.0)"
|
val expression = "`extension-function`(1.0)"
|
||||||
val result = evaluateExpression(expression, functions = FunctionExtensions(functions1 = mapOf("extension-function" to { x -> x * 2.0 })))
|
val result = evaluateExpression(
|
||||||
result?.shouldBeNear(2.0, 10E-6)
|
expression,
|
||||||
|
functions = FunctionExtensions(
|
||||||
|
functions1 = mapOf("extension-function" to { x ->
|
||||||
|
x * 2.0
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertNotNull(result)
|
||||||
|
assertEquals(2.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `extension function2 call`() {
|
fun `extension function2 call`() {
|
||||||
val expression = "extension(1.0, 1.0)"
|
val expression = "extension(1.0, 1.0)"
|
||||||
val result = evaluateExpression(expression, functions = FunctionExtensions(functions2 = mapOf("extension" to { x, y -> x + y })))
|
val result = evaluateExpression(
|
||||||
result?.shouldBeNear(2.0, 10E-6)
|
expression,
|
||||||
|
functions = FunctionExtensions(
|
||||||
|
functions2 = mapOf("extension" to { x, y ->
|
||||||
|
x + y
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertNotNull(result)
|
||||||
|
assertEquals(2.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `extension function3 call`() {
|
fun `extension function3 call`() {
|
||||||
val expression = "extension(1.0, 1.0, 1.0)"
|
val expression = "extension(1.0, 1.0, 1.0)"
|
||||||
val result = evaluateExpression(expression, functions = FunctionExtensions(functions3 = mapOf("extension" to { x, y, z -> x + y + z})))
|
val result = evaluateExpression(
|
||||||
result?.shouldBeNear(3.0, 10E-6)
|
expression,
|
||||||
|
functions = FunctionExtensions(
|
||||||
|
functions3 = mapOf("extension" to { x, y, z ->
|
||||||
|
x + y + z
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertNotNull(result)
|
||||||
|
assertEquals(3.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `extension function4 call`() {
|
fun `extension function4 call`() {
|
||||||
val expression = "extension(1.0, 1.0, 1.0, 1.0)"
|
val expression = "extension(1.0, 1.0, 1.0, 1.0)"
|
||||||
val result = evaluateExpression(expression, functions = FunctionExtensions(functions4 = mapOf("extension" to { x, y, z, w -> x + y + z + w})))
|
val result = evaluateExpression(
|
||||||
result?.shouldBeNear(4.0, 10E-6)
|
expression,
|
||||||
|
functions = FunctionExtensions(
|
||||||
|
functions4 = mapOf("extension" to { x, y, z, w ->
|
||||||
|
x + y + z + w
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertNotNull(result)
|
||||||
|
assertEquals(4.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `extension function5 call`() {
|
fun `extension function5 call`() {
|
||||||
val expression = "extension(1.0, 1.0, 1.0, 1.0, 1.0)"
|
val expression = "extension(1.0, 1.0, 1.0, 1.0, 1.0)"
|
||||||
val result = evaluateExpression(expression, functions = FunctionExtensions(functions5 = mapOf("extension" to { x, y, z, w, u -> x + y + z + w + u})))
|
val result = evaluateExpression(
|
||||||
result?.shouldBeNear(5.0, 10E-6)
|
expression,
|
||||||
|
functions = FunctionExtensions(
|
||||||
|
functions5 = mapOf("extension" to { x, y, z, w, u ->
|
||||||
|
x + y + z + w + u
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assertNotNull(result)
|
||||||
|
assertEquals(5.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,53 +1,62 @@
|
|||||||
import org.amshove.kluent.shouldBeNear
|
|
||||||
import org.openrndr.extra.expressions.evaluateExpression
|
import org.openrndr.extra.expressions.evaluateExpression
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertNotNull
|
||||||
|
|
||||||
class TestOperators {
|
class TestOperators {
|
||||||
@Test
|
@Test
|
||||||
fun `an addition operation`() {
|
fun `an addition operation`() {
|
||||||
val result = evaluateExpression("1 + 2")
|
val result = evaluateExpression("1 + 2")
|
||||||
result?.shouldBeNear(3.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(3.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a subtraction operation`() {
|
fun `a subtraction operation`() {
|
||||||
val result = evaluateExpression("1 - 2")
|
val result = evaluateExpression("1 - 2")
|
||||||
result?.shouldBeNear(-1.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(-1.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a modulus operation`() {
|
fun `a modulus operation`() {
|
||||||
val result = evaluateExpression("4 % 2")
|
val result = evaluateExpression("4 % 2")
|
||||||
result?.shouldBeNear(0.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(0.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a multiplication operation`() {
|
fun `a multiplication operation`() {
|
||||||
val result = evaluateExpression("4 * 2")
|
val result = evaluateExpression("4 * 2")
|
||||||
result?.shouldBeNear(8.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(8.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a division operation`() {
|
fun `a division operation`() {
|
||||||
val result = evaluateExpression("4 / 2")
|
val result = evaluateExpression("4 / 2")
|
||||||
result?.shouldBeNear(2.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(2.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a multiplication and addition operation`() {
|
fun `a multiplication and addition operation`() {
|
||||||
val result = evaluateExpression("4 * 2 + 1")
|
val result = evaluateExpression("4 * 2 + 1")
|
||||||
result?.shouldBeNear(9.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(9.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `an addition and multiplication`() {
|
fun `an addition and multiplication`() {
|
||||||
val result = evaluateExpression("4 + 2 * 3")
|
val result = evaluateExpression("4 + 2 * 3")
|
||||||
result?.shouldBeNear(10.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(10.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `unary minus`() {
|
fun `unary minus`() {
|
||||||
val result = evaluateExpression("-4.0")
|
val result = evaluateExpression("-4.0")
|
||||||
result?.shouldBeNear(-4.0, 10E-6)
|
assertNotNull(result)
|
||||||
|
assertEquals(-4.0, result, 10E-6)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,4 @@ dependencies {
|
|||||||
implementation(project(":orx-easing"))
|
implementation(project(":orx-easing"))
|
||||||
api(project(":orx-expression-evaluator"))
|
api(project(":orx-expression-evaluator"))
|
||||||
demoImplementation(project(":orx-jvm:orx-panel"))
|
demoImplementation(project(":orx-jvm:orx-panel"))
|
||||||
testImplementation(libs.kluent)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
import org.amshove.kluent.`should be`
|
|
||||||
import org.amshove.kluent.shouldBeNear
|
|
||||||
import org.openrndr.extra.keyframer.KeyframerChannel
|
|
||||||
import org.openrndr.extra.easing.Easing
|
import org.openrndr.extra.easing.Easing
|
||||||
|
import org.openrndr.extra.keyframer.KeyframerChannel
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertNull
|
||||||
|
|
||||||
class TestKeyframerChannel {
|
class TestKeyframerChannel {
|
||||||
@Test
|
@Test
|
||||||
fun `a keyframer channel without keys`() {
|
fun `a keyframer channel without keys`() {
|
||||||
val kfc = KeyframerChannel()
|
val kfc = KeyframerChannel()
|
||||||
kfc.value(0.0) `should be` null
|
assertNull(kfc.value(0.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -17,8 +16,11 @@ class TestKeyframerChannel {
|
|||||||
val kfc = KeyframerChannel()
|
val kfc = KeyframerChannel()
|
||||||
|
|
||||||
kfc.add(0.0, 1.0, Easing.Linear.function)
|
kfc.add(0.0, 1.0, Easing.Linear.function)
|
||||||
kfc.value(0.0)?.shouldBeNear(1.0, 10E-6)
|
val value = kfc.value(0.0)
|
||||||
kfc.value(-1.0) `should be` null
|
if (value != null) {
|
||||||
|
assertEquals(1.0, value, 10E-6)
|
||||||
|
}
|
||||||
|
assertNull(kfc.value(-1.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -26,7 +28,10 @@ class TestKeyframerChannel {
|
|||||||
val kfc = KeyframerChannel()
|
val kfc = KeyframerChannel()
|
||||||
kfc.add(0.0, 1.0, Easing.Linear.function)
|
kfc.add(0.0, 1.0, Easing.Linear.function)
|
||||||
kfc.add(1.0, 2.0, Easing.Linear.function)
|
kfc.add(1.0, 2.0, Easing.Linear.function)
|
||||||
kfc.value(0.0)?.shouldBeNear(1.0, 10E-6)
|
val value = kfc.value(0.0)
|
||||||
kfc.value(-1.0) `should be` null
|
if (value != null) {
|
||||||
|
assertEquals(1.0, value, 10E-6)
|
||||||
|
}
|
||||||
|
assertNull(kfc.value(-1.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import org.amshove.kluent.`should throw`
|
import org.junit.jupiter.api.assertThrows
|
||||||
import org.amshove.kluent.invoking
|
|
||||||
import org.openrndr.extra.expressions.ExpressionException
|
import org.openrndr.extra.expressions.ExpressionException
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
|
||||||
@@ -27,14 +26,18 @@ class TestKeyframerErrors {
|
|||||||
val animation = Animation()
|
val animation = Animation()
|
||||||
val json = """
|
val json = """
|
||||||
"""
|
"""
|
||||||
invoking { animation.loadFromJsonString(json) } `should throw` (IllegalStateException::class)
|
assertThrows<IllegalStateException> {
|
||||||
|
animation.loadFromJsonString(json)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `loading a non existing json`() {
|
fun `loading a non existing json`() {
|
||||||
val animation = Animation()
|
val animation = Animation()
|
||||||
|
|
||||||
invoking { animation.loadFromJson(testFile("this-does-not-exist")) } `should throw` (IllegalArgumentException::class)
|
assertThrows<IllegalArgumentException> {
|
||||||
|
animation.loadFromJson(testFile("this-does-not-exist"))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
@@ -47,12 +50,12 @@ class TestKeyframerErrors {
|
|||||||
|
|
||||||
val animation = Animation()
|
val animation = Animation()
|
||||||
|
|
||||||
invoking {
|
assertThrows<ExpressionException> {
|
||||||
animation.loadFromJson(
|
animation.loadFromJson(
|
||||||
testFile("src/test/resources/error-reporting/time-01.json"),
|
testFile("src/test/resources/error-reporting/time-01.json"),
|
||||||
format = KeyframerFormat.SIMPLE
|
format = KeyframerFormat.SIMPLE
|
||||||
)
|
)
|
||||||
} `should throw` ExpressionException::class //`with message` "Error loading from '${testName("src/test/resources/error-reporting/time-01.json")}': error in keys[0].'time': parser error in expression: ')('; [line: 1, character: 0 , near: [@0,0:0=')',<21>,1:0] ]"
|
} //`with message` "Error loading from '${testName("src/test/resources/error-reporting/time-01.json")}': error in keys[0].'time': parser error in expression: ')('; [line: 1, character: 0 , near: [@0,0:0=')',<21>,1:0] ]"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,34 +67,34 @@ class TestKeyframerErrors {
|
|||||||
@Test
|
@Test
|
||||||
fun `loading a json with a faulty time expression (2) `() {
|
fun `loading a json with a faulty time expression (2) `() {
|
||||||
val animation = Animation()
|
val animation = Animation()
|
||||||
invoking {
|
assertThrows<ExpressionException> {
|
||||||
animation.loadFromJson(
|
animation.loadFromJson(
|
||||||
testFile("src/test/resources/error-reporting/time-02.json"),
|
testFile("src/test/resources/error-reporting/time-02.json"),
|
||||||
format = KeyframerFormat.SIMPLE
|
format = KeyframerFormat.SIMPLE
|
||||||
)
|
)
|
||||||
} `should throw` ExpressionException::class //`with message` "Error loading from '${testName("src/test/resources/error-reporting/time-02.json")}': error in keys[0].'time': error in evaluation of 'doesNotExist': unresolved variable: 'doesNotExist'"
|
} //`with message` "Error loading from '${testName("src/test/resources/error-reporting/time-02.json")}': error in keys[0].'time': error in evaluation of 'doesNotExist': unresolved variable: 'doesNotExist'"
|
||||||
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
fun `loading a json with a non-existing easing`() {
|
fun `loading a json with a non-existing easing`() {
|
||||||
val animation = Animation()
|
val animation = Animation()
|
||||||
invoking {
|
assertThrows<ExpressionException> {
|
||||||
animation.loadFromJson(
|
animation.loadFromJson(
|
||||||
testFile("src/test/resources/error-reporting/easing.json"),
|
testFile("src/test/resources/error-reporting/easing.json"),
|
||||||
format = KeyframerFormat.SIMPLE
|
format = KeyframerFormat.SIMPLE
|
||||||
)
|
)
|
||||||
} `should throw` ExpressionException::class //`with message` "Error loading from '${testName("src/test/resources/error-reporting/easing.json")}': error in keys[0].'easing': unknown easing name 'garble'"
|
} //`with message` "Error loading from '${testName("src/test/resources/error-reporting/easing.json")}': error in keys[0].'easing': unknown easing name 'garble'"
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `loading a json with a faulty value (1)`() {
|
fun `loading a json with a faulty value (1)`() {
|
||||||
val animation = Animation()
|
val animation = Animation()
|
||||||
|
|
||||||
invoking {
|
assertThrows<ExpressionException> {
|
||||||
animation.loadFromJson(
|
animation.loadFromJson(
|
||||||
testFile("src/test/resources/error-reporting/value-01.json"),
|
testFile("src/test/resources/error-reporting/value-01.json"),
|
||||||
format = KeyframerFormat.SIMPLE
|
format = KeyframerFormat.SIMPLE
|
||||||
)
|
)
|
||||||
} `should throw` ExpressionException::class //`with message` "Error loading from '${testName("src/test/resources/error-reporting/value-01.json")}': error in keys[0].'x': error in evaluation of 'garble': unresolved variable: 'garble'"
|
} //`with message` "Error loading from '${testName("src/test/resources/error-reporting/value-01.json")}': error in keys[0].'x': error in evaluation of 'garble': unresolved variable: 'garble'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ tasks.withType<KotlinCompile> {
|
|||||||
dependencies {
|
dependencies {
|
||||||
antlr(libs.antlr.core)
|
antlr(libs.antlr.core)
|
||||||
implementation(libs.antlr.runtime)
|
implementation(libs.antlr.runtime)
|
||||||
testImplementation(libs.kluent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.getByName("compileKotlin").dependsOn("generateGrammarSource")
|
tasks.getByName("compileKotlin").dependsOn("generateGrammarSource")
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ dependencies {
|
|||||||
implementation(libs.kotlin.scriptingJSR223)
|
implementation(libs.kotlin.scriptingJSR223)
|
||||||
implementation(libs.kotlin.coroutines)
|
implementation(libs.kotlin.coroutines)
|
||||||
demoImplementation(libs.kotlin.coroutines)
|
demoImplementation(libs.kotlin.coroutines)
|
||||||
testImplementation(libs.kluent)
|
|
||||||
testImplementation(libs.kotest.runner)
|
testImplementation(libs.kotest.runner)
|
||||||
testImplementation(libs.kotest.assertions)
|
testImplementation(libs.kotest.assertions)
|
||||||
testRuntimeOnly(libs.kotlin.reflect)
|
testRuntimeOnly(libs.kotlin.reflect)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import io.kotest.assertions.throwables.shouldThrowUnit
|
import io.kotest.assertions.throwables.shouldThrowUnit
|
||||||
import io.kotest.core.spec.style.DescribeSpec
|
import io.kotest.core.spec.style.DescribeSpec
|
||||||
import io.kotest.matchers.collections.shouldBeIn
|
|
||||||
import io.kotest.matchers.doubles.plusOrMinus
|
import io.kotest.matchers.doubles.plusOrMinus
|
||||||
import io.kotest.matchers.equals.shouldBeEqual
|
import io.kotest.matchers.equals.shouldBeEqual
|
||||||
import io.kotest.matchers.nulls.shouldBeNull
|
import io.kotest.matchers.nulls.shouldBeNull
|
||||||
@@ -134,11 +133,11 @@ class TestAnnotations : DescribeSpec({
|
|||||||
list[11].property?.name?.shouldBeEqual("o")
|
list[11].property?.name?.shouldBeEqual("o")
|
||||||
list[11].label shouldBeEqual "an option parameter"
|
list[11].label shouldBeEqual "an option parameter"
|
||||||
|
|
||||||
assertEquals(list[12].parameterType, ParameterType.Path)
|
assertEquals(ParameterType.Path, list[12].parameterType)
|
||||||
assertEquals(list[12].property?.name, "p")
|
assertEquals("p", list[12].property?.name)
|
||||||
assertEquals(list[12].label, "a path parameter")
|
assertEquals("a path parameter", list[12].label)
|
||||||
assertEquals(list[12].absolutePath, false)
|
assertEquals(false, list[12].absolutePath)
|
||||||
assertEquals(list[12].pathContext, "null")
|
assertEquals("null", list[12].pathContext)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ kotlin {
|
|||||||
@Suppress("UNUSED_VARIABLE")
|
@Suppress("UNUSED_VARIABLE")
|
||||||
val jvmTest by getting {
|
val jvmTest by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.kluent)
|
|
||||||
runtimeOnly(libs.kotlin.reflect)
|
runtimeOnly(libs.kotlin.reflect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user