/*! @file @id $Id$ */ // 1 2 3 4 5 6 7 8 // 45678901234567890123456789012345678901234567890123456789012345678901234567890 #include #include #include #include #include #include #include class TemplateMatrixTest: public CppUnit::TestFixture { public: template void initFromArray1() { Matrix m {1, 2, 3, 4, 5, 6, 7, 8}; CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]); CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]); CPPUNIT_ASSERT_EQUAL((T)3, m[0][2]); CPPUNIT_ASSERT_EQUAL((T)4, m[0][3]); CPPUNIT_ASSERT_EQUAL((T)5, m[1][0]); CPPUNIT_ASSERT_EQUAL((T)6, m[1][1]); CPPUNIT_ASSERT_EQUAL((T)7, m[1][2]); CPPUNIT_ASSERT_EQUAL((T)8, m[1][3]); } template void initFromArray2() { Matrix m(1, 2, 3, 4, 5, 6, 7, 8); CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]); CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]); CPPUNIT_ASSERT_EQUAL((T)3, m[0][2]); CPPUNIT_ASSERT_EQUAL((T)4, m[0][3]); CPPUNIT_ASSERT_EQUAL((T)5, m[1][0]); CPPUNIT_ASSERT_EQUAL((T)6, m[1][1]); CPPUNIT_ASSERT_EQUAL((T)7, m[1][2]); CPPUNIT_ASSERT_EQUAL((T)8, m[1][3]); } template void initFromArray3() { Matrix m({1, 2, 3, 4, 5, 6, 7, 8}); CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]); CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]); CPPUNIT_ASSERT_EQUAL((T)3, m[0][2]); CPPUNIT_ASSERT_EQUAL((T)4, m[0][3]); CPPUNIT_ASSERT_EQUAL((T)5, m[1][0]); CPPUNIT_ASSERT_EQUAL((T)6, m[1][1]); CPPUNIT_ASSERT_EQUAL((T)7, m[1][2]); CPPUNIT_ASSERT_EQUAL((T)8, m[1][3]); } template void initFromOtherMatrix() { Matrix m1(1, 2, 3, 4, 5, 6, 7, 8); m1[1][2] = 13; Matrix m2(m1); m1[0][2] = 16; m2[0][0] = 0; CPPUNIT_ASSERT_EQUAL((T)1, m1[0][0]); CPPUNIT_ASSERT_EQUAL((T)2, m1[0][1]); CPPUNIT_ASSERT_EQUAL((T)16, m1[0][2]); CPPUNIT_ASSERT_EQUAL((T)4, m1[0][3]); CPPUNIT_ASSERT_EQUAL((T)5, m1[1][0]); CPPUNIT_ASSERT_EQUAL((T)6, m1[1][1]); CPPUNIT_ASSERT_EQUAL((T)13, m1[1][2]); CPPUNIT_ASSERT_EQUAL((T)8, m1[1][3]); CPPUNIT_ASSERT_EQUAL((T)0, m2[0][0]); CPPUNIT_ASSERT_EQUAL((T)2, m2[0][1]); CPPUNIT_ASSERT_EQUAL((T)3, m2[0][2]); CPPUNIT_ASSERT_EQUAL((T)4, m2[0][3]); CPPUNIT_ASSERT_EQUAL((T)5, m2[1][0]); CPPUNIT_ASSERT_EQUAL((T)6, m2[1][1]); CPPUNIT_ASSERT_EQUAL((T)13, m2[1][2]); CPPUNIT_ASSERT_EQUAL((T)8, m2[1][3]); } template void initFromDefault() { Matrix m; CPPUNIT_ASSERT_EQUAL((T)0, m[0][0]); CPPUNIT_ASSERT_EQUAL((T)0, m[0][1]); CPPUNIT_ASSERT_EQUAL((T)0, m[1][0]); CPPUNIT_ASSERT_EQUAL((T)0, m[1][1]); } template void access() { Matrix m1(1, 2, 3, 4, 5, 6, 7, 8); for (size_t row(0); row<2; ++row) for (size_t column(0); column<4; ++column) CPPUNIT_ASSERT_EQUAL(m1(row, column), m1[row][column]); } template void equality() { Matrix m1(1, 2, 3, 4, 5, 6, 7, 8); Matrix m2(1, 2, 3, 4, 5, 6, 7, 8); Matrix m3(1, 2, 3, 4, 5, 6, 7, 9); Matrix m4(9, 2, 3, 4, 5, 6, 7, 8); CPPUNIT_ASSERT(m1==m2); CPPUNIT_ASSERT(m1!=m3); CPPUNIT_ASSERT(m1!=m4); } CPPUNIT_TEST_SUITE(TemplateMatrixTest); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromArray3); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST_SUITE_END(); }; CPPUNIT_TEST_SUITE_REGISTRATION(TemplateMatrixTest); class VariableMatrixTest: public CppUnit::TestFixture { public: template void initFromArray1() { Matrix m(2,4, 1, 2, 3, 4, 5, 6, 7, 8); CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]); CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]); CPPUNIT_ASSERT_EQUAL((T)3, m[0][2]); CPPUNIT_ASSERT_EQUAL((T)4, m[0][3]); CPPUNIT_ASSERT_EQUAL((T)5, m[1][0]); CPPUNIT_ASSERT_EQUAL((T)6, m[1][1]); CPPUNIT_ASSERT_EQUAL((T)7, m[1][2]); CPPUNIT_ASSERT_EQUAL((T)8, m[1][3]); } template void initFromArray2() { Matrix m(2, 4, 1, 2, 3, 4, 5, 6, 7, 8); CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]); CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]); CPPUNIT_ASSERT_EQUAL((T)3, m[0][2]); CPPUNIT_ASSERT_EQUAL((T)4, m[0][3]); CPPUNIT_ASSERT_EQUAL((T)5, m[1][0]); CPPUNIT_ASSERT_EQUAL((T)6, m[1][1]); CPPUNIT_ASSERT_EQUAL((T)7, m[1][2]); CPPUNIT_ASSERT_EQUAL((T)8, m[1][3]); } template void initFromOtherMatrix() { Matrix m1(2, 4, 1, 2, 3, 4, 5, 6, 7, 8); m1[1][2] = 13; Matrix m2(m1); m1[0][2] = 16; m2[0][0] = 0; CPPUNIT_ASSERT_EQUAL((T)1, m1[0][0]); CPPUNIT_ASSERT_EQUAL((T)2, m1[0][1]); CPPUNIT_ASSERT_EQUAL((T)16, m1[0][2]); CPPUNIT_ASSERT_EQUAL((T)4, m1[0][3]); CPPUNIT_ASSERT_EQUAL((T)5, m1[1][0]); CPPUNIT_ASSERT_EQUAL((T)6, m1[1][1]); CPPUNIT_ASSERT_EQUAL((T)13, m1[1][2]); CPPUNIT_ASSERT_EQUAL((T)8, m1[1][3]); CPPUNIT_ASSERT_EQUAL((T)0, m2[0][0]); CPPUNIT_ASSERT_EQUAL((T)2, m2[0][1]); CPPUNIT_ASSERT_EQUAL((T)3, m2[0][2]); CPPUNIT_ASSERT_EQUAL((T)4, m2[0][3]); CPPUNIT_ASSERT_EQUAL((T)5, m2[1][0]); CPPUNIT_ASSERT_EQUAL((T)6, m2[1][1]); CPPUNIT_ASSERT_EQUAL((T)13, m2[1][2]); CPPUNIT_ASSERT_EQUAL((T)8, m2[1][3]); } template void initFromDefault() { Matrix m(2, 4); CPPUNIT_ASSERT_EQUAL((T)0, m[0][0]); CPPUNIT_ASSERT_EQUAL((T)0, m[0][1]); CPPUNIT_ASSERT_EQUAL((T)0, m[1][0]); CPPUNIT_ASSERT_EQUAL((T)0, m[1][1]); } template void access() { Matrix m1(2, 4, 1, 2, 3, 4, 5, 6, 7, 8); for (size_t row(0); row<2; ++row) for (size_t column(0); column<4; ++column) CPPUNIT_ASSERT_EQUAL(m1(row, column), m1[row][column]); } template void equality() { Matrix m1(2, 4, 1, 2, 3, 4, 5, 6, 7, 8); Matrix m2(2, 4, 1, 2, 3, 4, 5, 6, 7, 8); Matrix m3(2, 4, 1, 2, 3, 4, 5, 6, 7, 9); Matrix m4(2, 4, 9, 2, 3, 4, 5, 6, 7, 8); CPPUNIT_ASSERT(m1==m2); CPPUNIT_ASSERT(m1!=m3); CPPUNIT_ASSERT(m1!=m4); } CPPUNIT_TEST_SUITE(VariableMatrixTest); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray1); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromArray2); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(initFromOtherMatrix); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(access); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST(equality); CPPUNIT_TEST_SUITE_END(); }; CPPUNIT_TEST_SUITE_REGISTRATION(VariableMatrixTest); int main(int argc, char** argv) try { std::ofstream ofs((*argv+std::string(".xml")).c_str()); CppUnit::TextUi::TestRunner runner; runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), ofs)); runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); return runner.run() ? 0 : 1; } catch (std::exception& e) { std::cerr<<"***Exception: "<