add linear system test
Some checks failed
Linux arm64 / Build (push) Has been cancelled

This commit is contained in:
2024-05-14 22:39:15 +02:00
parent e6d0785009
commit a4036ae36d

View File

@@ -1,6 +1,25 @@
#include "Vect.h"
#include "test_assert.h"
const static int EXECUTION_COUNT = 100000;
static constexpr int MATRIX_MAX_SIZE = 7;
static int GetRandomSize() {
return rand() % MATRIX_MAX_SIZE + 1;
}
static int GetRandomInt() {
return GetRandomSize();
}
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
Matrix matrix {a_Raw, a_Column};
std::generate(matrix.GetLineIterator(0), matrix.GetLineIterator(a_Raw), []() { return GetRandomInt(); });
return matrix;
}
void TestVect() {
Vect vect1 {{3, 2, {
1, 2,
@@ -41,8 +60,22 @@ void TestVectAffine() {
test_assert(!aff.IsElementOf(Matrix::ColumnVector({1, 2, 3})));
}
void TestLinearSystem() {
for (std::size_t i = 0; i < EXECUTION_COUNT; i++) {
Vect vect = GetRandomMatrix(GetRandomSize(), GetRandomSize());
Matrix systeme = vect.GetLinearSystem();
for (std::size_t j = 0; j < vect.GetCardinal(); j++) {
Matrix nullMatrix {systeme.GetColumnCount(), 1};
test_assert(systeme * vect.GetVector(j) == nullMatrix);
}
}
}
int main() {
TestVect();
TestVectAffine();
TestLinearSystem();
return 0;
}