OpenWalnut  1.4.0
WValueSetBase_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 WVALUESETBASE_TEST_H
00026 #define WVALUESETBASE_TEST_H
00027 
00028 #include <cxxtest/TestSuite.h>
00029 
00030 #include "../WValueSetBase.h"
00031 #include "../WDataHandlerEnums.h"
00032 
00033 /**
00034  * Dummy class for testing the abstract class WValueSetBase
00035  */
00036 class Dummy : public WValueSetBase
00037 {
00038 friend class WValueSetBaseTest;
00039 
00040 public:
00041     /**
00042      * Standard constructor of Dummy class.
00043      */
00044     Dummy()
00045         : WValueSetBase( 0, 1, W_DT_INT8 )
00046     {
00047     }
00048 
00049     /**
00050      * Constructor of Dummy class for testing
00051      * \param dimension tensor dimension
00052      */
00053     explicit Dummy( char dimension )
00054         : WValueSetBase( 0, dimension, W_DT_INT8 )
00055     {
00056     }
00057 
00058     /**
00059      * Destructor.
00060      */
00061     virtual ~Dummy()
00062     {
00063     }
00064 
00065     /**
00066      * Get the size.
00067      *
00068      * \return The size.
00069      */
00070     virtual size_t size() const
00071     {
00072         return 255;
00073     }
00074 
00075     /**
00076      * Get the raw size.
00077      *
00078      * \return The raw size.
00079      */
00080     virtual size_t rawSize() const
00081     {
00082         return 255;
00083     }
00084 
00085     /**
00086      * Get the value.
00087      *
00088      * \return The value at position i.
00089      */
00090     virtual double getScalarDouble( size_t /* i */ ) const
00091     {
00092         return 255;
00093     }
00094 
00095     /**
00096      * \return The i-th WValue stored in this value set. There are size() such scalars.
00097      */
00098     virtual WValue< double > getWValueDouble( size_t /*i*/ ) const
00099     {
00100         return WValue< double >( size() );
00101     }
00102 
00103     /**
00104      * This method returns the smallest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
00105      * smallest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
00106      *
00107      * \return the smallest value in the data.
00108      */
00109     virtual double getMinimumValue() const
00110     {
00111         return 0.0;
00112     }
00113 
00114     /**
00115      * This method returns the largest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
00116      * largest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
00117      *
00118      * \return the largest value in the data.
00119      */
00120     virtual double getMaximumValue() const
00121     {
00122         return 255.0;
00123     }
00124 };
00125 
00126 /**
00127  * Testing abstract class via a Dummy class derived esp. for this purpose.
00128  */
00129 class WValueSetBaseTest : public CxxTest::TestSuite
00130 {
00131 public:
00132     /**
00133      *  Checks if the Dummy is instanceable.
00134      */
00135     void testInstantiation( void )
00136     {
00137         Dummy d;
00138     }
00139 
00140     /**
00141      *  Checks if the dimension using the dummy is right
00142      */
00143     void testDimension( void )
00144     {
00145         Dummy d1;
00146         TS_ASSERT_EQUALS( d1.dimension(), 1 );
00147         Dummy d2( 2 );
00148         TS_ASSERT_EQUALS( d2.dimension(), 2 );
00149     }
00150     /**
00151      *  Checks if the dimension using the dummy is right
00152      */
00153     void testDataType( void )
00154     {
00155         Dummy d1;
00156         TS_ASSERT_EQUALS( d1.getDataType(), W_DT_INT8 );
00157     }
00158 };
00159 
00160 #endif  // WVALUESETBASE_TEST_H