#include "Solver.h" #include "test_assert.h" #include #include #include #include static constexpr int EXECUTION_COUNT = 1000; static constexpr int KERNEL_CHECKS = 100; static constexpr int MATRIX_MAX_SIZE = 9; static const Solver solver; static int GetRandomInt() { return rand() % 11 - 5; } 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; } static bool Test() { Matrix matrix = GetRandomMatrix(rand() % MATRIX_MAX_SIZE + 1, rand() % MATRIX_MAX_SIZE + 1); 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(); } } Matrix copy = matrix; Vect kernel = solver.Kernel(std::move(copy)); Matrix nullVector {matrix.GetRawCount(), 1}; nullVector.Fill(0.0); for (std::size_t i = 0; i < kernel.GetCardinal(); i++) { test_assert(matrix * kernel.GetVector(i) == nullVector); } for (std::size_t i = 0; i < KERNEL_CHECKS; i++) { Matrix vector = GetRandomMatrix(kernel.GetDimension(), 1); test_assert(kernel.IsElementOf(vector) == (matrix * vector == nullVector)); } Vect kernel2 = solver.Kernel(kernel.GetLinearSystem()); test_assert(kernel == kernel2); return true; } int main() { srand(time(0)); std::vector> results; // appelle la fonction Test() en parallèle for (int i = 0; i < EXECUTION_COUNT; i++) { auto handle = std::async(std::launch::async, &Test); results.push_back(std::move(handle)); } for (auto& result : results) { if (!result.get()) return EXIT_FAILURE; } return EXIT_SUCCESS; }