X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=tests%2Fmatrix.cpp;fp=tests%2Fmatrix.cpp;h=10e3ffd97e8284705ef398d27887c579372d947a;hb=eb02e224876676a2d78f7305456a7d6f67d3dee2;hp=0000000000000000000000000000000000000000;hpb=6ff13022b53830d35283905d562c2ef3af198cc1;p=libs%2Fmath.git diff --git a/tests/matrix.cpp b/tests/matrix.cpp new file mode 100644 index 0000000..10e3ffd --- /dev/null +++ b/tests/matrix.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +using namespace Msp; + +class MatrixTests: public Test::RegisteredTest +{ +public: + MatrixTests(); + + static const char *get_name() { return "Matrix"; } + +private: + void multiply(); + void invert(); +}; + + +MatrixTests::MatrixTests() +{ + add(&MatrixTests::multiply, "Multiplication"); + add(&MatrixTests::invert, "Inversion"); +} + +void MatrixTests::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 + }; + + LinAl::Matrix a(data); + LinAl::Matrix b(data+6); + EXPECT(a*b == (LinAl::Matrix(data+12))); + EXPECT(b*a == (LinAl::Matrix(data+21))); +} + +template +bool is_identity(const LinAl::Matrix &m) +{ + for(unsigned i=0; i1e-10) + return false; + return true; +} + +void MatrixTests::invert() +{ + static double data[] = + { + 1, 4, 2, 4, 8, 6, 2, 2, 4 + }; + + LinAl::SquareMatrix m(data); + LinAl::SquareMatrix i = LinAl::invert(m); + EXPECT(is_identity(i*m)); +}