91 lines
2.1 KiB
C++
91 lines
2.1 KiB
C++
#include <filesystem>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
#include "IO.h"
|
|
#include "Solver.h"
|
|
#include "test_assert.h"
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
const static int EXECUTION_COUNT = 100;
|
|
static constexpr int MATRIX_MAX_SIZE = 5;
|
|
|
|
static unsigned int GetRandomInt() {
|
|
return rand() % MATRIX_MAX_SIZE + 1;
|
|
}
|
|
|
|
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++) {
|
|
matrix.at(i, j) = GetRandomInt();
|
|
}
|
|
}
|
|
|
|
return matrix;
|
|
}
|
|
|
|
void TestRectangular(const Matrix& system, const Matrix& origin) {
|
|
Solver solver;
|
|
|
|
VectAffine solution = solver.RectangularSystem(std::move(Matrix(system)), origin);
|
|
|
|
for (std::size_t i = 0; i < solution.GetBase().GetCardinal(); i++) {
|
|
Matrix vector = solution.GetBase().GetVector(i) + solution.GetOrigin();
|
|
for (std::size_t j = 0; j < system.GetRawCount(); j++) {
|
|
Matrix line = system.SubMatrix(j, 0, 1, system.GetColumnCount());
|
|
test_assert(line * vector == origin.SubMatrix(j, 0, 1, 1));
|
|
}
|
|
}
|
|
}
|
|
|
|
void RandomRectangular() {
|
|
for (int i = 0; i < EXECUTION_COUNT; i++) {
|
|
|
|
Matrix system = GetRandomMatrix(GetRandomInt(), GetRandomInt());
|
|
|
|
if (system.GetColumnCount() == system.GetRawCount())
|
|
continue;
|
|
|
|
Matrix origin = GetRandomMatrix(system.GetRawCount(), 1);
|
|
|
|
std::cout << "PIPI\n";
|
|
|
|
TestRectangular(system, origin);
|
|
}
|
|
}
|
|
|
|
void TestKernelImage() {
|
|
std::string path = "test";
|
|
for (const auto& entry : fs::directory_iterator(path)) {
|
|
std::string fileName = entry.path().string();
|
|
|
|
std::cout << "Opening " << fileName << " ...\n";
|
|
|
|
std::ifstream in {fileName};
|
|
|
|
Matrix mat, imageMat, noyauMat;
|
|
in >> mat >> imageMat >> noyauMat;
|
|
|
|
Vect image {std::move(imageMat)};
|
|
Vect noyau {std::move(noyauMat)};
|
|
|
|
Solver solver;
|
|
|
|
Matrix copy = mat;
|
|
|
|
Vect imageCalc = solver.Image(std::move(copy));
|
|
Vect kernelCalc = solver.Kernel(std::move(mat));
|
|
|
|
test_assert(imageCalc == image);
|
|
test_assert(kernelCalc == noyau);
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
TestKernelImage();
|
|
RandomRectangular();
|
|
return 0;
|
|
} |