OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WMatrixSym_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WMATRIXSYM_TEST_H
26 #define WMATRIXSYM_TEST_H
27 
28 #include <string>
29 #include <vector>
30 
31 #include <cxxtest/TestSuite.h>
32 
33 #include "../../exceptions/WOutOfBounds.h"
34 #include "../WMatrixSym.h"
35 
36 /**
37  * Unit test this LookUp table class. All test performed on matrices with double as element type.
38  */
39 class WMatrixSymTest : public CxxTest::TestSuite
40 {
41 public:
42  /**
43  * Only the Elements of the upper/lower sym. Matrix should be stored.
44  */
46  {
47  WMatrixSymDBL t( 3 );
48  TS_ASSERT_EQUALS( t.m_data.size(), 3 );
49  }
50 
51  /**
52  * Access to elements on main diagonal is forbidden. Then other acess
53  * should be symmetric.
54  */
55  void testAccessOn3x3Matrix( void )
56  {
57  WMatrixSymDBL t( 3 );
58  double mydata[] = { 1.6, 0.2, 7.7 }; // NOLINT
59  std::vector< double > data( mydata, mydata + sizeof( mydata ) / sizeof( double ) );
60  t.setData( data );
61  TS_ASSERT_EQUALS( t( 1, 2 ), 7.7 );
62  TS_ASSERT_EQUALS( t( 2, 1 ), 7.7 );
63  }
64 
65  /**
66  * If new elements are set via the setData() method then it has to be
67  * checked if the dimension is valid for the number of elements which
68  * are given.
69  */
71  {
72  WMatrixSymDBL t( 4 );
73  double mydata[] = { 1.6, 0.2, 7.7 }; // NOLINT
74  std::vector< double > data( mydata, mydata + sizeof( mydata ) / sizeof( double ) );
75  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
76  }
77 
78  /**
79  * Accessing diagonal elements is forbidden and an exception should be thrown
80  */
82  {
83  WMatrixSymDBL t( 4 );
84  double mydata[] = { 1.6, 0.2, 7.7 }; // NOLINT
85  std::vector< double > data( mydata, mydata + sizeof( mydata ) / sizeof( double ) );
86  TS_ASSERT_THROWS_EQUALS( t( 0, 0 ), WOutOfBounds &e, std::string( e.what() ),
87  "Invalid Element Access ( 0, 0 ). No diagonal elements or indices bigger than 4 are allowed." );
88  }
89 };
90 
91 #endif // WMATRIXSYM_TEST_H