allow tests in release mode
All checks were successful
Linux arm64 / Build (push) Successful in 6m40s

This commit is contained in:
2024-05-04 12:42:26 +02:00
parent 851080c7a4
commit f5a282c455
6 changed files with 80 additions and 38 deletions

43
test/test_assert.h Normal file
View File

@@ -0,0 +1,43 @@
#pragma once
/**
* \file Test.h
* \brief File containing unit testing utilities
*/
#include <cstdlib>
#include <iostream>
/**
* \def TEST_SUCCESSFUL
* \brief Used in tests to indicate that a test was successful
*/
#define TEST_SUCCESSFUL 0
/**
* \def TEST_FAILED
* \brief Used in tests to indicate that a test failed
*/
#define TEST_FAILED 1
#ifndef __FUNCTION_NAME__
#ifdef _WIN32
#define __FUNCTION_NAME__ __FUNCTION__
#else
#define __FUNCTION_NAME__ __PRETTY_FUNCTION__
#endif
#endif
/**
* \def test_assert
* \param ... The expression to evaluate
* \brief Evaluates the expression and exits the program if not valid.
* \note It works like a basic assert() but also in release mode
*/
#define test_assert(...) \
if (!static_cast<bool>(__VA_ARGS__)) { \
std::cout << __FILE__ << ":" << __LINE__ << ": " << __FUNCTION_NAME__ << ": Assertion failed !\n"; \
std::cout << " " << __LINE__ << " |\t" << #__VA_ARGS__ << std::endl; \
std::exit(TEST_FAILED); \
}

View File

@@ -1,10 +1,6 @@
#include "Gauss.h"
#include "Matrix.h"
#include <cassert>
#ifdef NDEBUG
#error "Il faut être en debug mode ! xmake f -m debug"
#endif
#include "test_assert.h"
struct Test {
Matrix mat;
@@ -37,7 +33,7 @@ static const std::vector<Test> TEST_MATRICES = {
void test() {
for (Test test : TEST_MATRICES) {
Gauss::GaussJordan(test.mat, true, true);
assert(test.mat == test.res);
test_assert(test.mat == test.res);
}
}

View File

@@ -1,5 +1,6 @@
#include "Solver.h"
#include <cassert>
#include "test_assert.h"
#include <cstdlib>
#include <future>
#include <iostream>
@@ -42,18 +43,18 @@ static void Test() {
nullVector.Fill(0.0);
for (std::size_t i = 0; i < kernel.GetCardinal(); i++) {
assert(matrix * kernel.GetVector(i) == nullVector);
test_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));
test_assert(kernel.IsElementOf(vector) == (matrix * vector == nullVector));
}
Vect kernel2 = solver.Kernel(kernel.GetLinearSystem());
assert(kernel == kernel2);
test_assert(kernel == kernel2);
}
int main() {
@@ -61,6 +62,7 @@ int main() {
std::vector<std::future<void>> 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));

View File

@@ -1,25 +1,25 @@
#include "NR.h"
#include <cassert>
#include "test_assert.h"
static void test() {
assert((NR {1, 5} == NR {5, 25}));
assert((NR {1, 5} != NR {4, 25}));
test_assert((NR {1, 5} == NR {5, 25}));
test_assert((NR {1, 5} != NR {4, 25}));
assert(NR {2} == NR {1} + 1);
assert(NR {1} == (NR {1, 4} + NR {3, 4}));
assert((NR {-3, -4} == NR {1, 2} + NR {1, 4}));
test_assert(NR {2} == NR {1} + 1);
test_assert(NR {1} == (NR {1, 4} + NR {3, 4}));
test_assert((NR {-3, -4} == NR {1, 2} + NR {1, 4}));
assert((NR {-1, 4} == NR {1, 4} - NR {1, 2}));
assert((NR {1, -4} == NR {1, 4} - NR {1, 2}));
assert((-NR {1, 4} == NR {1, 4} - NR {1, 2}));
test_assert((NR {-1, 4} == NR {1, 4} - NR {1, 2}));
test_assert((NR {1, -4} == NR {1, 4} - NR {1, 2}));
test_assert((-NR {1, 4} == NR {1, 4} - NR {1, 2}));
assert((NR {2} == NR {4, 3} * NR {3, 2}));
assert((NR {3, 5} == NR {4, 5} * NR {3, 4}));
test_assert((NR {2} == NR {4, 3} * NR {3, 2}));
test_assert((NR {3, 5} == NR {4, 5} * NR {3, 4}));
assert((NR {21, 16} == NR {7, 8} / NR {6, 9}));
test_assert((NR {21, 16} == NR {7, 8} / NR {6, 9}));
assert((NR {4, 3} == NR {3, 4}.Inverse()));
test_assert((NR {4, 3} == NR {3, 4}.Inverse()));
}
int main(int argc, char** argv) {

View File

@@ -1,10 +1,10 @@
#include <cassert>
#include <filesystem>
#include <fstream>
#include <iostream>
#include "IO.h"
#include "Solver.h"
#include "test_assert.h"
namespace fs = std::filesystem;
@@ -39,8 +39,8 @@ void TestKernelImage() {
Solver solver;
assert(solver.Image(mat) == image);
assert(solver.Kernel(mat) == noyau);
test_assert(solver.Image(mat) == image);
test_assert(solver.Kernel(mat) == noyau);
}
}

View File

@@ -1,5 +1,5 @@
#include "Vect.h"
#include <cassert>
#include "test_assert.h"
void TestVect() {
Vect vect1 {{3, 2, {
@@ -22,22 +22,23 @@ void TestVect() {
0, 0,
1, 11,
}}};
assert(vect1 == vect3);
assert(vect2 == vect4);
assert(vect1 != vect2);
assert(vect2 != vect3);
assert(vect3 != vect4);
assert(vect1.IsElementOf(Matrix::ColumnVector({3, 7, 11})));
assert(!vect1.IsElementOf(Matrix::ColumnVector({3, 7, 12})));
test_assert(vect1 == vect3);
test_assert(vect2 == vect4);
test_assert(vect1 != vect2);
test_assert(vect2 != vect3);
test_assert(vect3 != vect4);
test_assert(vect1.IsElementOf(Matrix::ColumnVector({3, 7, 11})));
test_assert(!vect1.IsElementOf(Matrix::ColumnVector({3, 7, 12})));
}
void TestVectAffine() {
VectAffine aff {Matrix {3, 1, {-2, 3, 7}}, Matrix::ColumnVector({5, 2, -8})};
VectAffine aff {Matrix::ColumnVector({-2, 3, 7}), Matrix::ColumnVector({5, 2, -8})};
assert(aff.IsElementOf(Matrix::ColumnVector({5, 2, -8})));
assert(aff.IsElementOf(Matrix::ColumnVector({3, 5, -1})));
assert(!aff.IsElementOf(Matrix::ColumnVector({1, 2, 3})));
test_assert(aff.IsElementOf(Matrix::ColumnVector({5, 2, -8})));
test_assert(aff.IsElementOf(Matrix::ColumnVector({3, 5, -1})));
test_assert(!aff.IsElementOf(Matrix::ColumnVector({1, 2, 3})));
}
int main() {