WMatrixSym_test.h

00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WMATRIXSYM_TEST_H
00026 #define WMATRIXSYM_TEST_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <cxxtest/TestSuite.h>
00032 
00033 #include "../../exceptions/WOutOfBounds.h"
00034 #include "../WMatrixSym.h"
00035 
00036 /**
00037  * Unit test this LookUp table class. All test performed on matrices with double as element type.
00038  */
00039 class WMatrixSymTest : public CxxTest::TestSuite
00040 {
00041 public:
00042     /**
00043      * Only the Elements of the upper/lower sym. Matrix should be stored.
00044      */
00045     void testOperatorOn3x3Matrix( void )
00046     {
00047         WMatrixSymDBL t( 3 );
00048         TS_ASSERT_EQUALS( t.m_data.size(), 3 );
00049     }
00050 
00051     /**
00052      * Access to elements on main diagonal is forbidden. Then other acess
00053      * should be symmetric.
00054      */
00055     void testAccessOn3x3Matrix( void )
00056     {
00057         WMatrixSymDBL t( 3 );
00058         double mydata[] = { 1.6, 0.2, 7.7 }; // NOLINT
00059         std::vector< double > data( mydata, mydata + sizeof( mydata ) / sizeof( double ) );
00060         t.setData( data );
00061         TS_ASSERT_EQUALS( t( 1, 2 ), 7.7 );
00062         TS_ASSERT_EQUALS( t( 2, 1 ), 7.7 );
00063     }
00064 
00065     /**
00066      * If new elements are set via the setData() method then it has to be
00067      * checked if the dimension is valid for the number of elements which
00068      * are given.
00069      */
00070     void testSetDataWithInvalidLengthForDimension( void )
00071     {
00072         WMatrixSymDBL t( 4 );
00073         double mydata[] = { 1.6, 0.2, 7.7 }; // NOLINT
00074         std::vector< double > data( mydata, mydata + sizeof( mydata ) / sizeof( double ) );
00075         TS_ASSERT_THROWS_EQUALS( t.setData( data ), WOutOfBounds &e, std::string( e.what() ), "Data vector length: 3 doesn't fit to number of rows and cols: 4" ); // NOLINT line length
00076     }
00077 
00078     /**
00079      * Accessing diagonal elements is forbidden and an exception should be thrown
00080      */
00081     void testInvalidAccessOnMainDiagonal( void )
00082     {
00083         WMatrixSymDBL t( 4 );
00084         double mydata[] = { 1.6, 0.2, 7.7 }; // NOLINT
00085         std::vector< double > data( mydata, mydata + sizeof( mydata ) / sizeof( double ) );
00086         TS_ASSERT_THROWS_EQUALS( t( 0, 0 ), WOutOfBounds &e, std::string( e.what() ),
00087                 "Invalid Element Access ( 0, 0 ). No diagonal elements or indices bigger than 4 are allowed." );
00088     }
00089 };
00090 
00091 #endif  // WMATRIXSYM_TEST_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends