From 44a1fb77d9199ce76fec21ee8aaa6df38e141bf0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 2 Jun 2019 16:22:24 +0300 Subject: [PATCH] Copy Matrix test cases for DynamicMatrix --- tests/dynamicmatrix.cpp | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/dynamicmatrix.cpp diff --git a/tests/dynamicmatrix.cpp b/tests/dynamicmatrix.cpp new file mode 100644 index 0000000..769945d --- /dev/null +++ b/tests/dynamicmatrix.cpp @@ -0,0 +1,67 @@ +#include +#include +#include + +using namespace std; +using namespace Msp; + +class DynamicMatrixTests: public Test::RegisteredTest +{ +private: + typedef LinAl::DynamicMatrix Matrixd; + +public: + DynamicMatrixTests(); + + static const char *get_name() { return "DynamicMatrix"; } + +private: + void multiply(); + void invert(); +}; + + +DynamicMatrixTests::DynamicMatrixTests() +{ + add(&DynamicMatrixTests::multiply, "Multiplication"); + add(&DynamicMatrixTests::invert, "Inversion"); +} + +void DynamicMatrixTests::multiply() +{ + static double data[] = + { + 1, 2, 1, 2, 1, 2, + 3, 0, 3, 0, 0, 3, + 3, 6, 3, 3, 6, 3, 6, 3, 6, + 9, 3, 9, 6 + }; + + Matrixd a(3, 2, data); + Matrixd b(2, 3, data+6); + EXPECT_EQUAL(a*b, Matrixd(3, 3, data+12)); + EXPECT_EQUAL(b*a, Matrixd(2, 2, data+21)); +} + +template +bool is_identity(const LinAl::DynamicMatrix &m) +{ + static const T limit = numeric_limits::epsilon()*4; + for(unsigned i=0; ilimit) + return false; + return true; +} + +void DynamicMatrixTests::invert() +{ + static double data[] = + { + 1, 4, 2, 4, 8, 6, 2, 2, 4 + }; + + Matrixd m(3, 3, data); + Matrixd i = LinAl::invert(m); + EXPECT(is_identity(i*m)); +} -- 2.45.2