OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WDataSetScalar_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 WDATASETSCALAR_TEST_H
26 #define WDATASETSCALAR_TEST_H
27 
28 #include <vector>
29 
30 #include <cxxtest/TestSuite.h>
31 
32 #include "../../common/WLogger.h"
33 
34 #include "../WDataSetScalar.h"
35 
36 /**
37  * Tests for the data set type containing only scalars.
38  */
39 class WDataSetScalarTest : public CxxTest::TestSuite
40 {
41 public:
42  /**
43  * Setup logger and other stuff for each test.
44  */
45  void setUp()
46  {
48  }
49 
50  /**
51  * Test if the interpolate function works reasonable.
52  */
53  void testInterpolate( void )
54  {
55  // create dummies, since they are needed in almost every test
56  boost::shared_ptr< WGrid > grid = boost::shared_ptr< WGrid >( new WGridRegular3D( 5, 3, 3 ) );
57  boost::shared_ptr< std::vector< double > > data = boost::shared_ptr< std::vector< double > >( new std::vector< double >( grid->size() ) );
58  for( size_t i = 0; i < grid->size(); ++i )
59  {
60  ( *data )[i] = i;
61  }
62  boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
63  WDataSetScalar ds( valueSet, grid );
64 
65  bool success = false;
66 
67  TS_ASSERT_EQUALS( ds.interpolate( WPosition::zero(), &success ), ( *data )[0] );
68  TS_ASSERT( success );
69  TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success ), ( *data )[1], 1e-9 );
70  TS_ASSERT( success );
71  TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success ), ( *data )[5], 1e-9 );
72  TS_ASSERT( success );
73  TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success ), ( *data )[6], 1e-9 );
74  TS_ASSERT( success );
75  TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success ), ( *data )[15], 1e-9 );
76  TS_ASSERT( success );
77  TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success ), ( *data )[16], 1e-9 );
78  TS_ASSERT( success );
79  TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success ), ( *data )[20], 1e-9 );
80  TS_ASSERT( success );
81  TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success ), ( *data )[21], 1e-9 );
82  TS_ASSERT( success );
83 
84  TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success ), 9.8, 1e-9 );
85  TS_ASSERT( success );
86  TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), 10.5, 1e-9 );
87  TS_ASSERT( success );
88  }
89 };
90 
91 #endif // WDATASETSCALAR_TEST_H