[orx-keyframer] Add support for backticked identifier names, replace spek tests
This commit is contained in:
@@ -3,55 +3,50 @@ 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
|
||||
import kotlin.test.Test
|
||||
|
||||
object TestExpressionErrors : Spek({
|
||||
class TestExpressionErrors {
|
||||
|
||||
describe("an expression with non-sensible writing") {
|
||||
@Test
|
||||
fun `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] ]"
|
||||
}
|
||||
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") {
|
||||
@Test
|
||||
fun `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] ]"
|
||||
}
|
||||
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") {
|
||||
@Test
|
||||
fun `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] ]"
|
||||
}
|
||||
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") {
|
||||
@Test
|
||||
fun `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)'"
|
||||
}
|
||||
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") {
|
||||
@Test
|
||||
fun `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'"
|
||||
}
|
||||
invoking {
|
||||
evaluateExpression(expression)
|
||||
} `should throw` ExpressionException::class `with message` "error in evaluation of 'notExisting+4': unresolved variable: 'notExisting'"
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,92 +1,138 @@
|
||||
import org.amshove.kluent.shouldBe
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
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
|
||||
import org.openrndr.math.map
|
||||
|
||||
object TestFunctionCall : Spek({
|
||||
describe("a function call") {
|
||||
import kotlin.test.Test
|
||||
class TestExpressions {
|
||||
|
||||
|
||||
@Test
|
||||
fun `a value reference`() {
|
||||
val expression = "someValue"
|
||||
val result = evaluateExpression(expression, variables= mapOf("someValue" to 5.0))
|
||||
result?.shouldBeEqualTo(5.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a backticked value reference`() {
|
||||
val expression = "`some-value`"
|
||||
val result = evaluateExpression(expression, variables= mapOf("some-value" to 5.0))
|
||||
result?.shouldBeEqualTo(5.0)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `a function call`() {
|
||||
val expression = "sqrt(4.0)"
|
||||
val result = evaluateExpression(expression)
|
||||
result?.shouldBeNear(2.0, 10E-6)
|
||||
}
|
||||
|
||||
describe("two function calls") {
|
||||
@Test
|
||||
fun `a function call with the name in backticks`() {
|
||||
val expression = "`sqrt`(4.0)"
|
||||
val result = evaluateExpression(expression)
|
||||
result?.shouldBeNear(2.0, 10E-6)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `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") {
|
||||
@Test
|
||||
fun `two argument max function call`() {
|
||||
val expression = "max(0.0, 4.0)"
|
||||
val result = evaluateExpression(expression)
|
||||
result?.shouldBeNear(4.0, 10E-6)
|
||||
}
|
||||
|
||||
describe("two argument function call") {
|
||||
@Test
|
||||
fun `two argument min function call`() {
|
||||
val expression = "min(8.0, 4.0)"
|
||||
val result = evaluateExpression(expression)
|
||||
result?.shouldBeNear(4.0, 10E-6)
|
||||
}
|
||||
|
||||
describe("three argument function call") {
|
||||
@Test
|
||||
fun `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") {
|
||||
@Test
|
||||
fun `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") {
|
||||
@Test
|
||||
fun `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") {
|
||||
@Test
|
||||
fun `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") {
|
||||
@Test
|
||||
fun `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") {
|
||||
@Test
|
||||
fun `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") {
|
||||
@Test
|
||||
fun `extension function1 call with dashed name in backticks`(){
|
||||
val expression = "`extension-function`(1.0)"
|
||||
val result = evaluateExpression(expression, functions = FunctionExtensions(functions1 = mapOf("extension-function" to { x -> x * 2.0 })))
|
||||
result?.shouldBeNear(2.0, 10E-6)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `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") {
|
||||
@Test
|
||||
fun `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") {
|
||||
@Test
|
||||
fun `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") {
|
||||
@Test
|
||||
fun `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)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
@@ -2,34 +2,31 @@ 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({
|
||||
import kotlin.test.Test
|
||||
|
||||
describe("a keyframer channel without keys") {
|
||||
class TestKeyframerChannel {
|
||||
@Test
|
||||
fun `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
|
||||
}
|
||||
kfc.value(0.0) `should be` null
|
||||
}
|
||||
describe("a keyframer channel with a single key") {
|
||||
|
||||
@Test
|
||||
fun `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
|
||||
}
|
||||
kfc.value(-1.0) `should be` null
|
||||
}
|
||||
describe("a keyframer channel with two keys") {
|
||||
|
||||
@Test
|
||||
fun `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
|
||||
}
|
||||
kfc.value(-1.0) `should be` null
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,110 +1,96 @@
|
||||
//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'"
|
||||
// }
|
||||
// }
|
||||
//})
|
||||
import org.amshove.kluent.`should throw`
|
||||
import org.amshove.kluent.invoking
|
||||
import kotlin.test.Test
|
||||
import org.openrndr.extra.keyframer.ExpressionException
|
||||
import org.openrndr.extra.keyframer.Keyframer
|
||||
import org.openrndr.extra.keyframer.KeyframerFormat
|
||||
import java.io.File
|
||||
import kotlin.IllegalStateException
|
||||
|
||||
private fun testFile(path: String): File {
|
||||
val test = File(".")
|
||||
return if (test.absolutePath.replace("\\","/").endsWith("orx-keyframer/.")) {
|
||||
File(path)
|
||||
} else {
|
||||
File("orx-keyframer/$path")
|
||||
}
|
||||
}
|
||||
|
||||
class TestKeyframerErrors {
|
||||
class Animation : Keyframer() {
|
||||
val position by Vector2Channel(arrayOf("x", "y"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `loading a faulty json`() {
|
||||
val animation = Animation()
|
||||
val json = """
|
||||
"""
|
||||
invoking { animation.loadFromJsonString(json) } `should throw` (IllegalStateException::class)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `loading a non existing json`() {
|
||||
val animation = Animation()
|
||||
|
||||
invoking { animation.loadFromJson(testFile("this-does-not-exist")) } `should throw` (IllegalArgumentException::class)
|
||||
|
||||
}
|
||||
@Test
|
||||
fun `loading a json with a faulty time expression (1)`() {
|
||||
|
||||
File(".").apply {
|
||||
println(this.absolutePath)
|
||||
}
|
||||
|
||||
|
||||
val animation = Animation()
|
||||
|
||||
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] ]>.
|
||||
|
||||
@Test
|
||||
fun `loading a json with a faulty time expression (2) `() {
|
||||
val animation = Animation()
|
||||
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'"
|
||||
|
||||
}
|
||||
@Test
|
||||
fun `loading a json with a non-existing easing`() {
|
||||
val animation = Animation()
|
||||
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'"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `loading a json with a faulty value (1)`() {
|
||||
val animation = Animation()
|
||||
|
||||
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'"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,53 @@
|
||||
import org.amshove.kluent.shouldBeNear
|
||||
import org.openrndr.extra.keyframer.evaluateExpression
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
import kotlin.test.Test
|
||||
|
||||
object TestOperators : Spek({
|
||||
describe("an addition operation") {
|
||||
class TestOperators {
|
||||
@Test
|
||||
fun `an addition operation`() {
|
||||
val result = evaluateExpression("1 + 2")
|
||||
result?.shouldBeNear(3.0, 10E-6)
|
||||
}
|
||||
describe("a subtraction operation") {
|
||||
|
||||
@Test
|
||||
fun `a subtraction operation`() {
|
||||
val result = evaluateExpression("1 - 2")
|
||||
result?.shouldBeNear(-1.0, 10E-6)
|
||||
}
|
||||
describe("a modulus operation") {
|
||||
|
||||
@Test
|
||||
fun `a modulus operation`() {
|
||||
val result = evaluateExpression("4 % 2")
|
||||
result?.shouldBeNear(0.0, 10E-6)
|
||||
}
|
||||
describe("a multiplication operation") {
|
||||
|
||||
@Test
|
||||
fun `a multiplication operation`() {
|
||||
val result = evaluateExpression("4 * 2")
|
||||
result?.shouldBeNear(8.0, 10E-6)
|
||||
}
|
||||
describe("a division operation") {
|
||||
|
||||
@Test
|
||||
fun `a division operation`() {
|
||||
val result = evaluateExpression("4 / 2")
|
||||
result?.shouldBeNear(2.0, 10E-6)
|
||||
}
|
||||
describe("a multiplication/addition operation") {
|
||||
|
||||
@Test
|
||||
fun `a multiplication and addition operation`() {
|
||||
val result = evaluateExpression("4 * 2 + 1")
|
||||
result?.shouldBeNear(9.0, 10E-6)
|
||||
}
|
||||
describe("an addition/multiplication") {
|
||||
|
||||
@Test
|
||||
fun `an addition and multiplication`() {
|
||||
val result = evaluateExpression("4 + 2 * 3")
|
||||
result?.shouldBeNear(10.0, 10E-6)
|
||||
}
|
||||
describe("unary minus") {
|
||||
|
||||
@Test
|
||||
fun `unary minus`() {
|
||||
val result = evaluateExpression("-4.0")
|
||||
result?.shouldBeNear(-4.0, 10E-6)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user