OpenWalnut  1.3.1
WDataSetDTI_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 WDATASETDTI_TEST_H
26 #define WDATASETDTI_TEST_H
27 
28 #include <vector>
29 
30 #include <cxxtest/TestSuite.h>
31 
32 #include "../../common/math/test/WTensorTraits.h"
33 #include "../../common/WLogger.h"
34 #include "../WDataSetDTI.h"
35 #include "../WGridRegular3D.h"
36 
37 /**
38  * Testsuite for unit tests of the WDataSetDTI class.
39  */
40 class WDataSetDTITest : public CxxTest::TestSuite
41 {
42 public:
43  /**
44  * Setup logger and other stuff for each test.
45  */
46  void setUp()
47  {
49  }
50 
51  /**
52  * Only values sets of order 1, dim 6 should be used to construct DTI datasets.
53  */
54  void testInstanziation( void )
55  {
56  float dataArray[6] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }; // NOLINT array init list
57  boost::shared_ptr< std::vector< float > > data =
58  boost::shared_ptr< std::vector< float > >(
59  new std::vector< float >( &dataArray[0], &dataArray[0] + sizeof( dataArray ) / sizeof( float ) ) );
60  boost::shared_ptr< WValueSetBase > newValueSet( new WValueSet< float >( 1, 6, data, W_DT_FLOAT ) );
61  boost::shared_ptr< WGrid > newGrid( new WGridRegular3D( 1, 1, 1 ) );
62  TS_ASSERT_THROWS_NOTHING( WDataSetDTI( newValueSet, newGrid ) );
63  }
64 
65  /**
66  * Accessing the i'th tensor is: getting the WValue at that position and
67  * transform it to a WTensorSym< 2, 3 >.
68  */
69  void testTensorAccess( void )
70  {
71  float dataArray[6] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }; // NOLINT array init list
72  boost::shared_ptr< std::vector< float > > data =
73  boost::shared_ptr< std::vector< float > >(
74  new std::vector< float >( &dataArray[0], &dataArray[0] + sizeof( dataArray ) / sizeof( float ) ) );
75  boost::shared_ptr< WValueSetBase > newValueSet( new WValueSet< float >( 1, 6, data, W_DT_FLOAT ) );
76  boost::shared_ptr< WGrid > newGrid( new WGridRegular3D( 1, 1, 1 ) );
77  WDataSetDTI dataset( newValueSet, newGrid );
79  expected( 0, 0 ) = 0.0;
80  expected( 0, 1 ) = 1.0;
81  expected( 0, 2 ) = 2.0;
82  expected( 1, 1 ) = 3.0;
83  expected( 1, 2 ) = 4.0;
84  expected( 2, 2 ) = 5.0;
85  TS_ASSERT_EQUALS( dataset.getTensor( 0 ), expected );
86  }
87 };
88 
89 #endif // WDATASETDTI_TEST_H