Improve tests

This commit is contained in:
Commander Tvis 2020-06-11 09:27:23 +07:00
parent e6f97c532b
commit 89fae39013
No known key found for this signature in database
GPG Key ID: 70D5F4DCB0972F1B
2 changed files with 16 additions and 10 deletions

View File

@ -215,7 +215,7 @@ class AsmGenerationContext<T>(
visitLoadAnyFromConstants(value, c)
}
internal fun visitLoadFromVariables(name: String, defaultValue: T? = null) = invokeMethodVisitor.run {
internal fun visitLoadFromVariables(name: String, defaultValue: T? = null): Unit = invokeMethodVisitor.run {
maxStack += 2
visitVarInsn(Opcodes.ALOAD, invokeArgumentsVar)
@ -241,6 +241,7 @@ class AsmGenerationContext<T>(
}
internal fun visitLoadAlgebra() {
maxStack++
invokeMethodVisitor.visitVarInsn(Opcodes.ALOAD, invokeThisVar)
invokeMethodVisitor.visitFieldInsn(

View File

@ -3,6 +3,8 @@ package scientifik.kmath.expressions
import scientifik.kmath.expressions.asm.AsmExpression
import scientifik.kmath.expressions.asm.AsmExpressionField
import scientifik.kmath.expressions.asm.asmField
import scientifik.kmath.expressions.asm.asmRing
import scientifik.kmath.operations.IntRing
import scientifik.kmath.operations.RealField
import kotlin.test.Test
import kotlin.test.assertEquals
@ -15,26 +17,29 @@ class AsmTest {
): Unit = assertEquals(expected = expected, actual = asmField(RealField, block)(arguments))
@Test
fun testConstantsSum() = testDoubleExpression(16.0) { const(8.0) + 8.0 }
fun testConstantsSum(): Unit = testDoubleExpression(16.0) { const(8.0) + 8.0 }
@Test
fun testVarsSum() = testDoubleExpression(1000.0, mapOf("x" to 500.0)) { variable("x") + 500.0 }
fun testVarsSum(): Unit = testDoubleExpression(1000.0, mapOf("x" to 500.0)) { variable("x") + 500.0 }
@Test
fun testProduct() = testDoubleExpression(24.0) { const(4.0) * const(6.0) }
fun testProduct(): Unit = testDoubleExpression(24.0) { const(4.0) * const(6.0) }
@Test
fun testConstantProduct() = testDoubleExpression(984.0) { const(8.0) * 123 }
fun testConstantProduct(): Unit = testDoubleExpression(984.0) { const(8.0) * 123 }
@Test
fun testSubtraction() = testDoubleExpression(2.0) { const(4.0) - 2.0 }
fun testVarsConstantProductVar(): Unit = testDoubleExpression(984.0, mapOf("x" to 8.0)) { variable("x") * 123 }
@Test
fun testDivision() = testDoubleExpression(64.0) { const(128.0) / 2 }
fun testSubtraction(): Unit = testDoubleExpression(2.0) { const(4.0) - 2.0 }
@Test
fun testDirectCall() = testDoubleExpression(4096.0) { binaryOperation("*", const(64.0), const(64.0)) }
fun testDivision(): Unit = testDoubleExpression(64.0) { const(128.0) / 2 }
// @Test
// fun testSine() = testDoubleExpression(0.0) { unaryOperation("sin", const(PI)) }
@Test
fun testDirectUnaryCall(): Unit = testDoubleExpression(64.0) { unaryOperation("+", const(64.0)) }
@Test
fun testDirectBinaryCall(): Unit = testDoubleExpression(4096.0) { binaryOperation("*", const(64.0), const(64.0)) }
}