+#include <msp/linal/matrix.h>
+#include <msp/linal/squarematrix.h>
+#include <msp/test/test.h>
+
+using namespace Msp;
+
+class MatrixTests: public Test::RegisteredTest<MatrixTests>
+{
+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<double, 3, 2> a(data);
+ LinAl::Matrix<double, 2, 3> b(data+6);
+ EXPECT(a*b == (LinAl::Matrix<double, 3, 3>(data+12)));
+ EXPECT(b*a == (LinAl::Matrix<double, 2, 2>(data+21)));
+}
+
+template<typename T, unsigned N>
+bool is_identity(const LinAl::Matrix<T, N, N> &m)
+{
+ for(unsigned i=0; i<N; ++i)
+ for(unsigned j=0; j<N; ++j)
+ if(abs(T(i==j)-m(i, j))>1e-10)
+ return false;
+ return true;
+}
+
+void MatrixTests::invert()
+{
+ static double data[] =
+ {
+ 1, 4, 2, 4, 8, 6, 2, 2, 4
+ };
+
+ LinAl::SquareMatrix<double, 3> m(data);
+ LinAl::SquareMatrix<double, 3> i = LinAl::invert(m);
+ EXPECT(is_identity(i*m));
+}