inverse tested

This commit is contained in:
Marc Wäckerlin
2016-08-22 15:04:38 +00:00
parent 549db697b7
commit 2f35c1e3a0
4 changed files with 210 additions and 62 deletions

View File

@@ -204,17 +204,41 @@ class TemplateMatrixTest: public CppUnit::TestFixture {
}
template<typename T>
void inv() {
Matrix<T,3,3> m(2, -1, 0,
1, 2, -2,
0, -1, 1);
const Matrix<T,3,3> res(0.5, 0, 0,
-0.2, 0.4, 0,
-1, 2, 5);
// const Matrix<T,3,3> res(0, 1, 2,
// -1, 2, 4,
// -1, 2, 5);
m.inv();
CPPUNIT_ASSERT_EQUAL(res, m);
{
Matrix<T,3,3> m(2, -1, 0,
1, 2, -2,
0, -1, 1);
const Matrix<T,3,3> res(0, 1, 2,
-1, 2, 4,
-1, 2, 5);
m.inv();
CPPUNIT_ASSERT(m.similar(res, 0.0001));
} {
Matrix<T,3,3> m(1, 2, 3,
0, 1, 4,
5, 6, 0);
const Matrix<T,3,3> res(-24, 18, 5,
20, -15, -4,
-5, 4, 1);
m.inv();
CPPUNIT_ASSERT_EQUAL(res, m);
} {
Matrix<T,3,3> m(1, 2, 3,
0, 4, 5,
1, 0, 6);
const Matrix<T,3,3> res((T)12/11, (T)-6/11, (T)-1/11,
(T)5/22, (T)3/22, (T)-5/22,
(T)-2/11, (T)1/11, (T)2/11);
m.inv();
CPPUNIT_ASSERT_EQUAL(res, m);
} {
Matrix<T,2,2> m(4, 3,
3, 2);
const Matrix<T,2,2> res(-2, 3,
3, -4);
m.inv();
CPPUNIT_ASSERT_EQUAL(res, m);
}
}
CPPUNIT_TEST_SUITE(TemplateMatrixTest);
CPPUNIT_TEST(initFromArray1<int>);
@@ -502,6 +526,32 @@ class VariableMatrixTest: public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(m2, m2.i());
CPPUNIT_ASSERT_EQUAL(m3, m3.i());
}
template<typename T>
void inv() {
{
Matrix<T> m(3, 3,
2, -1, 0,
1, 2, -2,
0, -1, 1);
const Matrix<T> res(3, 3,
0, 1, 2,
-1, 2, 4,
-1, 2, 5);
m.inv();
CPPUNIT_ASSERT(m.similar(res, 0.0001));
} {
Matrix<T> m(3, 3,
1, 2, 3,
0, 1, 4,
5, 6, 0);
const Matrix<T> res(3, 3,
-24, 18, 5,
20, -15, -4,
-5, 4, 1);
m.inv();
CPPUNIT_ASSERT_EQUAL(res, m);
}
}
CPPUNIT_TEST_SUITE(VariableMatrixTest);
CPPUNIT_TEST(initFromArray1<int>);
CPPUNIT_TEST(initFromArray1<long>);
@@ -583,6 +633,8 @@ class VariableMatrixTest: public CppUnit::TestFixture {
CPPUNIT_TEST(i<unsigned long>);
CPPUNIT_TEST(i<float>);
CPPUNIT_TEST(i<double>);
CPPUNIT_TEST(inv<float>);
CPPUNIT_TEST(inv<double>);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(VariableMatrixTest);