improve random_kernel test
All checks were successful
Linux arm64 / Build (push) Successful in 1m25s

This commit is contained in:
2024-03-14 21:54:13 +01:00
parent 13c9bc40db
commit 2724ca173d
3 changed files with 48 additions and 11 deletions

View File

@@ -6,6 +6,7 @@
#include <vector>
static constexpr int EXECUTION_COUNT = 100;
static constexpr int KERNEL_CHECKS = 100;
static constexpr int MATRIX_MAX_SIZE = 100;
static const Solver solver;
@@ -14,8 +15,8 @@ static unsigned int GetRandomInt() {
return rand() % MATRIX_MAX_SIZE + 1;
}
static void Test() {
Matrix matrix {GetRandomInt(), GetRandomInt()};
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
Matrix matrix {a_Raw, a_Column};
for (std::size_t i = 0; i < matrix.GetRawCount(); i++) {
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
@@ -23,10 +24,36 @@ static void Test() {
}
}
Vect vect1 = solver.Kernel(matrix);
Vect vect2 = solver.Kernel(vect1.GetLinearSystem());
return matrix;
}
assert(vect1 == vect2);
static void Test() {
Matrix matrix = GetRandomMatrix(GetRandomInt(), GetRandomInt());
for (std::size_t i = 0; i < matrix.GetRawCount(); i++) {
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
matrix.at(i, j) = GetRandomInt();
}
}
Vect kernel = solver.Kernel(matrix);
Matrix nullVector {matrix.GetRawCount(), 1};
nullVector.Fill(0.0);
for (std::size_t i = 0; i < kernel.GetCardinal(); i++) {
assert(matrix * kernel.GetVector(i) == nullVector);
}
for (std::size_t i = 0; i < KERNEL_CHECKS; i++) {
Matrix vector = GetRandomMatrix(kernel.GetDimension(), 1);
assert(kernel.IsElementOf(vector) == (matrix * vector == nullVector));
}
Vect kernel2 = solver.Kernel(kernel.GetLinearSystem());
assert(kernel == kernel2);
}
int main() {