Write tests

This commit is contained in:
Iaroslav 2020-06-13 16:16:57 +07:00
parent 223d238c43
commit e65d1e43cf
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
2 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,75 @@
package scietifik.kmath.ast.asm
import scientifik.kmath.asm.asmField
import scientifik.kmath.asm.asmRing
import scientifik.kmath.asm.asmSpace
import scientifik.kmath.expressions.invoke
import scientifik.kmath.operations.ByteRing
import scientifik.kmath.operations.RealField
import kotlin.test.Test
import kotlin.test.assertEquals
class TestAsmAlgebras {
@Test
fun space() {
val res = ByteRing.asmSpace {
binaryOperation(
"+",
unaryOperation(
"+",
3.toByte() - (2.toByte() + (multiply(
add(const(1), const(1)),
2
) + 1.toByte()) * 3.toByte() - 1.toByte())
),
number(1)
) + variable("x") + zero
}("x" to 2.toByte())
assertEquals(16, res)
}
@Test
fun ring() {
val res = ByteRing.asmRing {
binaryOperation(
"+",
unaryOperation(
"+",
(3.toByte() - (2.toByte() + (multiply(
add(const(1), const(1)),
2
) + 1.toByte()))) * 3.0 - 1.toByte()
),
number(1)
) * const(2)
}()
assertEquals(24, res)
}
@Test
fun field() {
val res = RealField.asmField {
divide(binaryOperation(
"+",
unaryOperation(
"+",
(3.0 - (2.0 + (multiply(
add(const(1.0), const(1.0)),
2
) + 1.0))) * 3 - 1.0
),
number(1)
) / 2, const(2.0)) * one
}()
assertEquals(3.0, res)
}
}

View File

@ -0,0 +1,21 @@
package scietifik.kmath.ast.asm
import scientifik.kmath.asm.asmField
import scientifik.kmath.expressions.invoke
import scientifik.kmath.operations.RealField
import kotlin.test.Test
import kotlin.test.assertEquals
class TestAsmExpressions {
@Test
fun testUnaryOperationInvocation() {
val res = RealField.asmField { unaryOperation("+", variable("x")) }("x" to 2.0)
assertEquals(2.0, res)
}
@Test
fun testConstProductInvocation() {
val res = RealField.asmField { variable("x") * 2 }("x" to 2.0)
assertEquals(4.0, res)
}
}