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-02-18 11:17:28 +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
|
|
|
|
|
2022-06-14 16:27:32 +03:00
|
|
|
public open class RingVerifier<T, out A>(algebra: A, a: T, b: T, c: T, x: Number) :
|
2021-03-08 21:03:48 +03:00
|
|
|
SpaceVerifier<T, A>(algebra, a, b, c, x) where A : Ring<T>, A : ScaleOperations<T> {
|
|
|
|
|
2020-08-12 17:18:47 +03:00
|
|
|
override fun verify() {
|
|
|
|
super.verify()
|
|
|
|
|
|
|
|
algebra {
|
2020-12-20 16:48:38 +03:00
|
|
|
assertEquals(a + b, b + a, "Addition in $algebra is not commutative.")
|
2020-08-12 17:18:47 +03:00
|
|
|
assertEquals(a * b * c, a * (b * c), "Multiplication in $algebra is not associative.")
|
|
|
|
assertEquals(c * (a + b), (c * a) + (c * b), "Multiplication in $algebra is not distributive.")
|
|
|
|
assertEquals(a * one, one * a, "$one in $algebra is not a neutral multiplication element.")
|
|
|
|
assertEquals(a, one * a, "$one in $algebra is not a neutral multiplication element.")
|
|
|
|
assertEquals(a, a * one, "$one in $algebra is not a neutral multiplication element.")
|
|
|
|
assertEquals(a, one * a, "$one in $algebra is not a neutral multiplication element.")
|
|
|
|
assertEquals(a, a * one * one, "Multiplication by $one in $algebra is not idempotent.")
|
|
|
|
assertEquals(a, a * one * one * one, "Multiplication by $one in $algebra is not idempotent.")
|
|
|
|
assertEquals(a, a * one * one * one * one, "Multiplication by $one in $algebra is not idempotent.")
|
|
|
|
assertEquals(zero, a * zero, "Multiplication by $zero in $algebra doesn't give $zero.")
|
|
|
|
assertEquals(zero, zero * a, "Multiplication by $zero in $algebra doesn't give $zero.")
|
|
|
|
assertEquals(a * zero, a * zero, "Multiplication by $zero in $algebra doesn't give $zero.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|