2021-03-23 18:13:35 +03:00
|
|
|
/*
|
2022-08-19 15:59:13 +03:00
|
|
|
* Copyright 2018-2022 KMath contributors.
|
2021-11-16 14:04:44 +03:00
|
|
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
2021-03-23 18:13:35 +03:00
|
|
|
*/
|
|
|
|
|
2021-02-18 11:17:28 +03:00
|
|
|
package space.kscience.kmath.testutils
|
2020-08-12 17:18:47 +03:00
|
|
|
|
2021-04-14 23:26:21 +03:00
|
|
|
import space.kscience.kmath.operations.Ring
|
2021-03-08 21:03:48 +03:00
|
|
|
import space.kscience.kmath.operations.ScaleOperations
|
2021-02-18 11:17:28 +03:00
|
|
|
import space.kscience.kmath.operations.invoke
|
2020-08-12 17:18:47 +03:00
|
|
|
import kotlin.test.assertEquals
|
|
|
|
import kotlin.test.assertNotEquals
|
|
|
|
|
2022-06-14 16:27:32 +03:00
|
|
|
public open class SpaceVerifier<T, out S>(
|
2021-03-08 21:03:48 +03:00
|
|
|
override val algebra: S,
|
2022-06-14 16:27:32 +03:00
|
|
|
public val a: T,
|
|
|
|
public val b: T,
|
|
|
|
public val c: T,
|
|
|
|
public val x: Number,
|
2021-04-14 23:26:21 +03:00
|
|
|
) : AlgebraicVerifier<T, Ring<T>> where S : Ring<T>, S : ScaleOperations<T> {
|
2020-08-12 17:18:47 +03:00
|
|
|
override fun verify() {
|
|
|
|
algebra {
|
|
|
|
assertEquals(a + b + c, a + (b + c), "Addition in $algebra is not associative.")
|
|
|
|
assertEquals(x * (a + b), x * a + x * b, "Addition in $algebra is not distributive.")
|
|
|
|
assertEquals((a + b) * x, a * x + b * x, "Addition in $algebra is not distributive.")
|
|
|
|
assertEquals(a + zero, zero + a, "$zero in $algebra is not a neutral addition element.")
|
|
|
|
assertEquals(a, a + zero, "$zero in $algebra is not a neutral addition element.")
|
|
|
|
assertEquals(a, zero + a, "$zero in $algebra is not a neutral addition element.")
|
|
|
|
assertEquals(a - b, -(b - a), "Subtraction in $algebra is not anti-commutative.")
|
|
|
|
assertNotEquals(a - b - c, a - (b - c), "Subtraction in $algebra is associative.")
|
|
|
|
assertEquals(x * (a - b), x * a - x * b, "Subtraction in $algebra is not distributive.")
|
|
|
|
assertEquals(a, a - zero, "$zero in $algebra is not a neutral addition element.")
|
|
|
|
assertEquals(a * x, x * a, "Multiplication by scalar in $algebra is not commutative.")
|
|
|
|
assertEquals(x * (a + b), (x * a) + (x * b), "Multiplication by scalar in $algebra is not distributive.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|