OpenWalnut 1.2.5
|
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 WDATASETSCALAR_TEST_H 00026 #define WDATASETSCALAR_TEST_H 00027 00028 #include <vector> 00029 00030 #include <cxxtest/TestSuite.h> 00031 00032 #include "../../common/WLogger.h" 00033 00034 #include "../WDataSetScalar.h" 00035 00036 /** 00037 * Tests for the data set type containing only scalars. 00038 */ 00039 class WDataSetScalarTest : public CxxTest::TestSuite 00040 { 00041 public: 00042 /** 00043 * Setup logger and other stuff for each test. 00044 */ 00045 void setUp() 00046 { 00047 WLogger::startup(); 00048 } 00049 00050 /** 00051 * Test if the interpolate function works reasonable. 00052 */ 00053 void testInterpolate( void ) 00054 { 00055 // create dummies, since they are needed in almost every test 00056 boost::shared_ptr< WGrid > grid = boost::shared_ptr< WGrid >( new WGridRegular3D( 5, 3, 3 ) ); 00057 boost::shared_ptr< std::vector< double > > data = boost::shared_ptr< std::vector< double > >( new std::vector< double >( grid->size() ) ); 00058 for( size_t i = 0; i < grid->size(); ++i ) 00059 { 00060 ( *data )[i] = i; 00061 } 00062 boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) ); 00063 WDataSetScalar ds( valueSet, grid ); 00064 00065 bool success = false; 00066 00067 TS_ASSERT_EQUALS( ds.interpolate( WPosition::zero(), &success ), ( *data )[0] ); 00068 TS_ASSERT( success ); 00069 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success ), ( *data )[1], 1e-9 ); 00070 TS_ASSERT( success ); 00071 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success ), ( *data )[5], 1e-9 ); 00072 TS_ASSERT( success ); 00073 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success ), ( *data )[6], 1e-9 ); 00074 TS_ASSERT( success ); 00075 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success ), ( *data )[15], 1e-9 ); 00076 TS_ASSERT( success ); 00077 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success ), ( *data )[16], 1e-9 ); 00078 TS_ASSERT( success ); 00079 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success ), ( *data )[20], 1e-9 ); 00080 TS_ASSERT( success ); 00081 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success ), ( *data )[21], 1e-9 ); 00082 TS_ASSERT( success ); 00083 00084 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success ), 9.8, 1e-9 ); 00085 TS_ASSERT( success ); 00086 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), 10.5, 1e-9 ); 00087 TS_ASSERT( success ); 00088 } 00089 }; 00090 00091 #endif // WDATASETSCALAR_TEST_H