/* * Tiny Vector Matrix Library * Dense Vector Matrix Libary of Tiny size using Expression Templates * * Copyright (C) 2001 - 2003 Olaf Petzold * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: TestDimension.h,v 1.1 2004/04/24 11:55:15 opetzold Exp $ */ #ifndef TVMET_TEST_DIMENSION_H #define TVMET_TEST_DIMENSION_H #include #include #include template class TestDimension : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( TestDimension ); CPPUNIT_TEST( small_add ); CPPUNIT_TEST( Mtx ); CPPUNIT_TEST( MtM ); CPPUNIT_TEST( MMt ); CPPUNIT_TEST( MMt ); CPPUNIT_TEST( trans_MM ); CPPUNIT_TEST( Row ); CPPUNIT_TEST( Col ); CPPUNIT_TEST_SUITE_END(); public: TestDimension() { } public: // cppunit interface /** cppunit hook for fixture set up. */ void setUp(); /** cppunit hook for fixture tear down. */ void tearDown(); protected: void small_add(); void Mtx(); void MtM(); void MMt(); void trans_MM(); void Row(); void Col(); }; /***************************************************************************** * Implementation part I (cppunit part) ****************************************************************************/ template void TestDimension::setUp() { } template void TestDimension::tearDown() { } /***************************************************************************** * Implementation part II ****************************************************************************/ template void TestDimension::small_add() { using namespace tvmet; Matrix M1, M2, M3; M1 = 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1; M2 = M1; M3 = M1 + M2; CPPUNIT_ASSERT( all_elements(M3 == 2) ); } template void TestDimension::Mtx() { using namespace tvmet; Matrix M1; Vector v1; Vector r(0), v2(0); M1 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12, 13,14,15, 16,17,18; v1 = 1,2,3,4,5,6; r = trans(M1)*v1; v2 = Mtx_prod(M1, v1); CPPUNIT_ASSERT( all_elements(r == v2) ); } template void TestDimension::MtM() { using namespace tvmet; Matrix M1; Matrix M2; Matrix r(0), M3(0); M1 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12, 13,14,15, 16,17,18; M2 = 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12; r = prod(trans(M1),M2); M3 = MtM_prod(M1, M2); CPPUNIT_ASSERT( all_elements(r == M3) ); } template void TestDimension::MMt() { using namespace tvmet; Matrix M1; Matrix M2; Matrix M3(0), r(0); M1 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12; M2 = 1,2,3,4, 5,6,7,8; r = M1*trans(M2); M3 = MMt_prod(M1,M2); CPPUNIT_ASSERT( all_elements(r == M3) ); } template void TestDimension::trans_MM() { using namespace tvmet; Matrix M1; Matrix M2; Matrix r(0), M3(0); M1 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12, 13,14,15, 16,17,18; M2 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12, 13,14,15,16,17,18; r = trans(prod(M1, M2)); M3 = trans_prod(M1, M2); CPPUNIT_ASSERT( all_elements(r == M3) ); } template void TestDimension::Row() { using namespace tvmet; Matrix M; Vector v; Vector r0(1,2,3); Vector r5(16,17,18); M = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12, 13,14,15, 16,17,18; v = row(M, 0); CPPUNIT_ASSERT( all_elements(v == r0) ); v = row(M, 5); CPPUNIT_ASSERT( all_elements(v == r5) ); } template void TestDimension::Col() { using namespace tvmet; Matrix M; Vector v; Vector c0(1,7,13); Vector c5(6,12,18); M = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12, 13,14,15,16,17,18; v = col(M, 0); CPPUNIT_ASSERT( all_elements(v == c0) ); v = col(M, 5); CPPUNIT_ASSERT( all_elements(v == c5) ); } #endif // TVMET_TEST_DIMENSION_H // Local Variables: // mode:C++ // End: