add basic test
This commit is contained in:
@@ -134,6 +134,20 @@ bool Matrix::IsInversed() const {
|
||||
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) {
|
||||
int r = -1;
|
||||
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
||||
|
||||
@@ -37,6 +37,8 @@ class Matrix {
|
||||
|
||||
bool IsInversed() const;
|
||||
|
||||
bool operator==(const Matrix& other) const;
|
||||
|
||||
long double& operator[](std::size_t indice);
|
||||
|
||||
long double& at(std::size_t ligne, std::size_t colonne);
|
||||
|
||||
45
test/mainTest.cpp
Normal file
45
test/mainTest.cpp
Normal 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;
|
||||
}
|
||||
12
xmake.lua
12
xmake.lua
@@ -6,6 +6,18 @@ target("Pivot")
|
||||
set_rundir("$(projectdir)/matricies")
|
||||
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
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user