[orx-jvm] Move panel, gui, dnk3, keyframer, triangulation to orx-jvm

This commit is contained in:
Edwin Jakobs
2021-06-27 21:32:24 +02:00
parent 5814acef8f
commit 874d49779f
159 changed files with 22 additions and 21 deletions

View File

@@ -0,0 +1,57 @@
import org.amshove.kluent.`should throw`
import org.amshove.kluent.`with message`
import org.amshove.kluent.invoking
import org.openrndr.extra.keyframer.ExpressionException
import org.openrndr.extra.keyframer.evaluateExpression
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import java.lang.IllegalStateException
object TestExpressionErrors : Spek({
describe("an expression with non-sensible writing") {
val expression = ")("
it("should cause an exception to be thrown when evaluated") {
invoking {
evaluateExpression(expression)
} `should throw` ExpressionException::class `with message` "parser error in expression: ')('; [line: 1, character: 0 , near: [@0,0:0=')',<21>,1:0] ]"
}
}
describe("an expression with equality instead of assign") {
val expression = "a == 5"
it("should cause an exception to be thrown when evaluated") {
invoking {
evaluateExpression(expression)
} `should throw` ExpressionException::class `with message` "parser error in expression: 'a == 5'; [line: 1, character: 3 , near: [@3,3:3='=',<19>,1:3] ]"
}
}
describe("an expression trying to reassign a number") {
val expression = "3 = 5"
it("should cause an exception to be thrown when evaluated") {
invoking {
evaluateExpression(expression)
} `should throw` ExpressionException::class `with message` "parser error in expression: '3 = 5'; [line: 1, character: 2 , near: [@2,2:2='=',<19>,1:2] ]"
}
}
describe("an expression that uses non-existing functions") {
val expression = "notExisting(5)"
it("should cause an exception to be thrown when evaluated") {
invoking {
evaluateExpression(expression)
} `should throw` ExpressionException::class `with message` "error in evaluation of 'notExisting(5)': unresolved function: 'notExisting(x0)'"
}
}
describe("an expression that uses non-existing variables") {
val expression = "notExisting + 4"
it("should cause an exception to be thrown when evaluated") {
invoking {
evaluateExpression(expression)
} `should throw` ExpressionException::class `with message` "error in evaluation of 'notExisting+4': unresolved variable: 'notExisting'"
}
}
})

View File

@@ -0,0 +1,92 @@
import org.amshove.kluent.shouldBeNear
import org.openrndr.extra.keyframer.FunctionExtensions
import org.openrndr.extra.keyframer.evaluateExpression
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
object TestFunctionCall : Spek({
describe("a function call") {
val expression = "sqrt(4.0)"
val result = evaluateExpression(expression)
result?.shouldBeNear(2.0, 10E-6)
}
describe("two function calls") {
val expression = "sqrt(4.0) * sqrt(4.0)"
val result = evaluateExpression(expression)
result?.shouldBeNear(4.0, 10E-6)
}
describe("two argument function call") {
val expression = "max(0.0, 4.0)"
val result = evaluateExpression(expression)
result?.shouldBeNear(4.0, 10E-6)
}
describe("two argument function call") {
val expression = "min(8.0, 4.0)"
val result = evaluateExpression(expression)
result?.shouldBeNear(4.0, 10E-6)
}
describe("three argument function call") {
val expression = "mix(8.0, 4.0, 0.5)"
val result = evaluateExpression(expression)
result?.shouldBeNear(6.0, 10E-6)
}
describe("five argument function call") {
val expression = "map(0.0, 1.0, 0.0, 8.0, 0.5)"
val result = evaluateExpression(expression)
result?.shouldBeNear(4.0, 10E-6)
}
describe("two argument function call, where argument order matters") {
val expression = "pow(2.0, 3.0)"
val result = evaluateExpression(expression)
result?.shouldBeNear(8.0, 10E-6)
}
describe("nested function call") {
val expression = "sqrt(min(8.0, 4.0))"
val result = evaluateExpression(expression)
result?.shouldBeNear(2.0, 10E-6)
}
describe("extension function0 call") {
val expression = "extension()"
val result = evaluateExpression(expression, functions = FunctionExtensions(functions0 = mapOf("extension" to { 2.0 })))
result?.shouldBeNear(2.0, 10E-6)
}
describe("extension function1 call") {
val expression = "extension(1.0)"
val result = evaluateExpression(expression, functions = FunctionExtensions(functions1 = mapOf("extension" to { x -> x * 2.0 })))
result?.shouldBeNear(2.0, 10E-6)
}
describe("extension function2 call") {
val expression = "extension(1.0, 1.0)"
val result = evaluateExpression(expression, functions = FunctionExtensions(functions2 = mapOf("extension" to { x, y -> x + y })))
result?.shouldBeNear(2.0, 10E-6)
}
describe("extension function3 call") {
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})))
result?.shouldBeNear(3.0, 10E-6)
}
describe("extension function4 call") {
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})))
result?.shouldBeNear(4.0, 10E-6)
}
describe("extension function5 call") {
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})))
result?.shouldBeNear(5.0, 10E-6)
}
})

View File

@@ -0,0 +1,35 @@
import org.amshove.kluent.`should be`
import org.amshove.kluent.shouldBeNear
import org.openrndr.extra.keyframer.KeyframerChannel
import org.openrndr.extras.easing.Easing
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
object TestKeyframerChannel : Spek({
describe("a keyframer channel without keys") {
val kfc = KeyframerChannel()
it ("should return null when asking for value before first key time") {
kfc.value(0.0) `should be` null
}
}
describe("a keyframer channel with a single key") {
val kfc = KeyframerChannel()
kfc.add(0.0, 1.0, Easing.Linear.function)
kfc.value(0.0)?.shouldBeNear(1.0, 10E-6)
it ("should return null when asking for value before first key time") {
kfc.value(-1.0) `should be` null
}
}
describe("a keyframer channel with two keys") {
val kfc = KeyframerChannel()
kfc.add(0.0, 1.0, Easing.Linear.function)
kfc.add(1.0, 2.0, Easing.Linear.function)
kfc.value(0.0)?.shouldBeNear(1.0, 10E-6)
it ("should return null when asking for value before first key time") {
kfc.value(-1.0) `should be` null
}
}
})

View File

@@ -0,0 +1,110 @@
import org.amshove.kluent.`should throw`
import org.amshove.kluent.`with message`
import org.amshove.kluent.invoking
import org.openrndr.extra.keyframer.ExpressionException
import org.openrndr.extra.keyframer.Keyframer
import org.openrndr.extra.keyframer.KeyframerFormat
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import java.io.File
import kotlin.IllegalStateException
private fun testFile(path: String) : File {
val test = File(".")
return if (test.absolutePath.endsWith("orx-keyframer/.")) {
File(path)
} else {
File("orx-keyframer/$path")
}
}
private fun testName(path: String) : String {
val test = File(".")
return (if (test.absolutePath.endsWith("orx-keyframer/.")) {
path
} else {
"orx-keyframer/$path"
}).replace("/", File.separator)
}
object TestKeyframerErrors : Spek({
class Animation : Keyframer() {
val position by Vector2Channel(arrayOf("x", "y"))
}
describe("loading a faulty json") {
val animation = Animation()
val json = """
"""
it("should throw an exception") {
invoking { animation.loadFromJsonString(json) } `should throw` (IllegalStateException::class)
}
}
describe("loading a non existing json") {
val animation = Animation()
it("should throw an exception") {
invoking { animation.loadFromJson(testFile("this-does-not-exist")) } `should throw` (IllegalArgumentException::class)
}
}
describe("loading a json with a faulty time expression (1)") {
File(".").apply {
println(this.absolutePath)
}
val animation = Animation()
it("should throw an exception") {
invoking {
animation.loadFromJson(
testFile("src/test/resources/error-reporting/time-01.json"),
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] ]"
}
}
// Paths.sep
//
//Expected <Error loading from 'orx-keyframer/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] ]>,
// actual <Error loading from 'orx-keyframer\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] ]>.
describe("loading a json with a faulty time expression (2) ") {
val animation = Animation()
it("should throw an exception") {
invoking {
animation.loadFromJson(
testFile("src/test/resources/error-reporting/time-02.json"),
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'"
}
}
describe("loading a json with a non-existing easing") {
val animation = Animation()
it("should throw an exception") {
invoking {
animation.loadFromJson(
testFile("src/test/resources/error-reporting/easing.json"),
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'"
}
}
describe("loading a json with a faulty value (1)") {
val animation = Animation()
it("should throw an exception") {
invoking {
animation.loadFromJson(
testFile("src/test/resources/error-reporting/value-01.json"),
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'"
}
}
})

View File

@@ -0,0 +1,39 @@
import org.amshove.kluent.shouldBeNear
import org.openrndr.extra.keyframer.evaluateExpression
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
object TestOperators : Spek({
describe("an addition operation") {
val result = evaluateExpression("1 + 2")
result?.shouldBeNear(3.0, 10E-6)
}
describe("a subtraction operation") {
val result = evaluateExpression("1 - 2")
result?.shouldBeNear(-1.0, 10E-6)
}
describe("a modulus operation") {
val result = evaluateExpression("4 % 2")
result?.shouldBeNear(0.0, 10E-6)
}
describe("a multiplication operation") {
val result = evaluateExpression("4 * 2")
result?.shouldBeNear(8.0, 10E-6)
}
describe("a division operation") {
val result = evaluateExpression("4 / 2")
result?.shouldBeNear(2.0, 10E-6)
}
describe("a multiplication/addition operation") {
val result = evaluateExpression("4 * 2 + 1")
result?.shouldBeNear(9.0, 10E-6)
}
describe("an addition/multiplication") {
val result = evaluateExpression("4 + 2 * 3")
result?.shouldBeNear(10.0, 10E-6)
}
describe("unary minus") {
val result = evaluateExpression("-4.0")
result?.shouldBeNear(-4.0, 10E-6)
}
})

View File

@@ -0,0 +1,5 @@
[
{
"easing": "garble"
}
]

View File

@@ -0,0 +1,5 @@
[
{
"time": ")("
}
]

View File

@@ -0,0 +1,5 @@
[
{
"time": "doesNotExist"
}
]

View File

@@ -0,0 +1,7 @@
[
{
"time": "0.0",
"x": "garble",
"y": "garble"
}
]