--- /dev/null
+#include <limits>
+#include <msp/linal/dynamicmatrix.h>
+#include <msp/test/test.h>
+
+using namespace std;
+using namespace Msp;
+
+class DynamicMatrixTests: public Test::RegisteredTest<DynamicMatrixTests>
+{
+private:
+ typedef LinAl::DynamicMatrix<double> 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<typename T>
+bool is_identity(const LinAl::DynamicMatrix<T> &m)
+{
+ static const T limit = numeric_limits<T>::epsilon()*4;
+ for(unsigned i=0; i<m.rows(); ++i)
+ for(unsigned j=0; j<m.columns(); ++j)
+ if(abs(T(i==j)-m(i, j))>limit)
+ 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));
+}