#include "Vect.h" #include "test_assert.h" #include const static int EXECUTION_COUNT = 100000; static constexpr int MATRIX_MAX_SIZE = 5; static int GetRandomSize() { return rand() % MATRIX_MAX_SIZE + 1; } static int GetRandomInt() { return GetRandomSize(); } static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) { Matrix matrix {a_Raw, a_Column}; std::generate(matrix.GetLineIterator(0), matrix.GetLineIterator(a_Raw), []() { return GetRandomInt(); }); return matrix; } void TestVect() { Vect vect1 {{3, 2, { 1, 2, 3, 4, 5, 6, }}}; Vect vect2 {{3, 2, { 1, 0, 0, 0, 0, 1, }}}; Vect vect3 {{3, 2, { 1, 3, 3, 7, 5, 11, }}}; Vect vect4 {{3, 2, { 1, 0, 0, 0, 1, 11, }}}; 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::ColumnVector({-2, 3, 7}), Matrix::ColumnVector({5, 2, -8})}; 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}))); } void TestLinearSystem() { for (std::size_t i = 0; i < EXECUTION_COUNT; i++) { Vect vect = GetRandomMatrix(GetRandomSize(), GetRandomSize()); Matrix systeme = vect.GetLinearSystem(); for (std::size_t j = 0; j < vect.GetCardinal(); j++) { Matrix nullMatrix {systeme.GetColumnCount(), 1}; test_assert(systeme * vect.GetVector(j) == nullMatrix); } } } int main() { srand(time(0)); TestVect(); TestVectAffine(); TestLinearSystem(); return 0; }