Replace kluent with kotlin.test (#361)

This commit is contained in:
Abe Pazos
2025-07-07 16:23:15 +02:00
committed by GitHub
parent 771e348631
commit 8323054519
19 changed files with 187 additions and 120 deletions

View File

@@ -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.keyframer.KeyframerChannel
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
class TestKeyframerChannel {
@Test
fun `a keyframer channel without keys`() {
val kfc = KeyframerChannel()
kfc.value(0.0) `should be` null
assertNull(kfc.value(0.0))
}
@Test
@@ -17,8 +16,11 @@ class TestKeyframerChannel {
val kfc = KeyframerChannel()
kfc.add(0.0, 1.0, Easing.Linear.function)
kfc.value(0.0)?.shouldBeNear(1.0, 10E-6)
kfc.value(-1.0) `should be` null
val value = kfc.value(0.0)
if (value != null) {
assertEquals(1.0, value, 10E-6)
}
assertNull(kfc.value(-1.0))
}
@Test
@@ -26,7 +28,10 @@ class TestKeyframerChannel {
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)
kfc.value(-1.0) `should be` null
val value = kfc.value(0.0)
if (value != null) {
assertEquals(1.0, value, 10E-6)
}
assertNull(kfc.value(-1.0))
}
}

View File

@@ -1,5 +1,4 @@
import org.amshove.kluent.`should throw`
import org.amshove.kluent.invoking
import org.junit.jupiter.api.assertThrows
import org.openrndr.extra.expressions.ExpressionException
import kotlin.test.Test
@@ -27,14 +26,18 @@ class TestKeyframerErrors {
val animation = Animation()
val json = """
"""
invoking { animation.loadFromJsonString(json) } `should throw` (IllegalStateException::class)
assertThrows<IllegalStateException> {
animation.loadFromJsonString(json)
}
}
@Test
fun `loading a non existing json`() {
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
@@ -47,12 +50,12 @@ class TestKeyframerErrors {
val animation = Animation()
invoking {
assertThrows<ExpressionException> {
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] ]"
} //`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
fun `loading a json with a faulty time expression (2) `() {
val animation = Animation()
invoking {
assertThrows<ExpressionException> {
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'"
} //`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
fun `loading a json with a non-existing easing`() {
val animation = Animation()
invoking {
assertThrows<ExpressionException> {
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'"
} //`with message` "Error loading from '${testName("src/test/resources/error-reporting/easing.json")}': error in keys[0].'easing': unknown easing name 'garble'"
}
@Test
fun `loading a json with a faulty value (1)`() {
val animation = Animation()
invoking {
assertThrows<ExpressionException> {
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'"
} //`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'"
}
}