add basic test

This commit is contained in:
2024-02-10 16:58:44 +01:00
parent 150e67e30b
commit 4c217a4b20
4 changed files with 73 additions and 0 deletions

View File

@@ -134,6 +134,20 @@ bool Matrix::IsInversed() const {
return true; return true;
} }
bool Matrix::operator==(const Matrix& other) const {
if (m_Lignes != other.m_Lignes || m_Colonnes != other.m_Colonnes)
return false;
for (std::size_t i = 0; i < m_Lignes; i++) {
for (std::size_t j = 0; j < m_Colonnes; j++) {
if (!IsEqualZero(at(i, j) - other.at(i, j)))
return false;
}
}
return true;
}
void Matrix::GaussNonJordan(bool reduite) { void Matrix::GaussNonJordan(bool reduite) {
int r = -1; int r = -1;
for (std::size_t j = 0; j < m_Colonnes; j++) { for (std::size_t j = 0; j < m_Colonnes; j++) {

View File

@@ -37,6 +37,8 @@ class Matrix {
bool IsInversed() const; bool IsInversed() const;
bool operator==(const Matrix& other) const;
long double& operator[](std::size_t indice); long double& operator[](std::size_t indice);
long double& at(std::size_t ligne, std::size_t colonne); long double& at(std::size_t ligne, std::size_t colonne);

45
test/mainTest.cpp Normal file
View File

@@ -0,0 +1,45 @@
#include "Matrix.h"
#include <cassert>
#ifdef NDEBUG
#error "Il faut être en debug mode ! xmake f -m debug"
#endif
struct Test{
Matrix mat;
Matrix res;
};
static const std::vector<Test> TEST_MATRICES = {
// test 1
{{3, 3, {
1, 2, 3,
4, 5, 6,
7, 8, 9,
}}, {3, 3, {
1, 0, -1,
0, 1, 2,
0, 0, 0,
}}},
// test 2
{{3, 3, {
4, 5, 6,
1, 2, 3,
7, 8, 9,
}}, {3, 3, {
1, 0, -1,
0, 1, 2,
0, 0, 0,
}}}
};
void test() {
for (Test test : TEST_MATRICES) {
test.mat.GaussJordan(true);
assert(test.mat == test.res);
}
}
int main(int argc, char** argv) {
test();
return 0;
}

View File

@@ -6,6 +6,18 @@ target("Pivot")
set_rundir("$(projectdir)/matricies") set_rundir("$(projectdir)/matricies")
set_languages("c++17") set_languages("c++17")
target("PivotTest")
set_kind("binary")
add_files("test/*.cpp", "src/Matrix.cpp")
add_includedirs("src")
set_default(false)
add_tests("compile_and_run")
set_rundir("$(projectdir)/matricies")
-- --
-- If you want to known more usage about xmake, please see https://xmake.io -- If you want to known more usage about xmake, please see https://xmake.io
-- --