Move complex related tests from kmath-core to kmath-complex

This commit is contained in:
Iaroslav Postovalov 2021-02-09 18:11:54 +07:00
parent da1713b3c6
commit b06f96c335
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
6 changed files with 36 additions and 31 deletions

View File

@ -46,8 +46,8 @@ private val PI_DIV_2 = Complex(PI / 2, 0)
* A field of [Complex].
*/
public object ComplexField : ExtendedField<Complex>, Norm<Complex, Complex>, RingWithNumbers<Complex> {
public override val zero: Complex by lazy { 0.0.toComplex() }
public override val one: Complex by lazy { 1.0.toComplex() }
public override val zero: Complex = 0.0.toComplex()
public override val one: Complex = 1.0.toComplex()
/**
* The imaginary unit.

View File

@ -36,23 +36,23 @@ public val Quaternion.r: Double
*/
public object QuaternionField : Field<Quaternion>, Norm<Quaternion, Quaternion>, PowerOperations<Quaternion>,
ExponentialOperations<Quaternion>, RingWithNumbers<Quaternion> {
override val zero: Quaternion by lazy { 0.toQuaternion() }
override val one: Quaternion by lazy { 1.toQuaternion() }
override val zero: Quaternion = 0.toQuaternion()
override val one: Quaternion = 1.toQuaternion()
/**
* The `i` quaternion unit.
*/
public val i: Quaternion by lazy { Quaternion(0, 1) }
public val i: Quaternion = Quaternion(0, 1)
/**
* The `j` quaternion unit.
*/
public val j: Quaternion by lazy { Quaternion(0, 0, 1) }
public val j: Quaternion = Quaternion(0, 0, 1)
/**
* The `k` quaternion unit.
*/
public val k: Quaternion by lazy { Quaternion(0, 0, 0, 1) }
public val k: Quaternion = Quaternion(0, 0, 0, 1)
public override fun add(a: Quaternion, b: Quaternion): Quaternion =
Quaternion(a.w + b.w, a.x + b.x, a.y + b.y, a.z + b.z)

View File

@ -1,7 +1,6 @@
package kscience.kmath.structures
package kscience.kmath.complex
import kscience.kmath.complex.Complex
import kscience.kmath.complex.complex
import kscience.kmath.structures.Buffer
import kotlin.test.Test
import kotlin.test.assertEquals
@ -11,4 +10,4 @@ class ComplexBufferSpecTest {
val buffer = Buffer.complex(20) { Complex(it.toDouble(), -it.toDouble()) }
assertEquals(Complex(5.0, -5.0), buffer[5])
}
}
}

View File

@ -0,0 +1,26 @@
package kscience.kmath.complex
import kscience.kmath.expressions.FunctionalExpressionField
import kscience.kmath.expressions.bind
import kscience.kmath.expressions.invoke
import kscience.kmath.expressions.symbol
import kscience.kmath.operations.invoke
import kotlin.test.Test
import kotlin.test.assertEquals
internal class ExpressionFieldForComplexTest {
val x by symbol
@Test
fun testComplex() {
val context = FunctionalExpressionField(ComplexField)
val expression = context {
val x = bind(x)
x * x + 2 * x + one
}
assertEquals(expression(x to Complex(1.0, 0.0)), Complex(4.0, 0.0))
//assertEquals(expression(), Complex(9.0, 0.0))
}
}

View File

@ -11,12 +11,6 @@ kotlin.sourceSets {
api(project(":kmath-memory"))
}
}
commonTest {
dependencies {
api(project(":kmath-complex"))
}
}
}
readme {

View File

@ -1,7 +1,6 @@
package kscience.kmath.expressions
import kscience.kmath.operations.RealField
import kscience.kmath.complex.*
import kscience.kmath.operations.invoke
import kotlin.test.Test
import kotlin.test.assertEquals
@ -23,19 +22,6 @@ class ExpressionFieldTest {
assertFails { expression() }
}
@Test
fun testComplex() {
val context = FunctionalExpressionField(ComplexField)
val expression = context {
val x = bind(x)
x * x + 2 * x + one
}
assertEquals(expression(x to Complex(1.0, 0.0)), Complex(4.0, 0.0))
//assertEquals(expression(), Complex(9.0, 0.0))
}
@Test
fun separateContext() {
fun <T> FunctionalExpressionField<T, *>.expression(): Expression<T> {