OpenWalnut  1.4.0
WValueSetBase_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 WVALUESETBASE_TEST_H
26 #define WVALUESETBASE_TEST_H
27 
28 #include <cxxtest/TestSuite.h>
29 
30 #include "../WValueSetBase.h"
31 #include "../WDataHandlerEnums.h"
32 
33 /**
34  * Dummy class for testing the abstract class WValueSetBase
35  */
36 class Dummy : public WValueSetBase
37 {
38 friend class WValueSetBaseTest;
39 
40 public:
41  /**
42  * Standard constructor of Dummy class.
43  */
45  : WValueSetBase( 0, 1, W_DT_INT8 )
46  {
47  }
48 
49  /**
50  * Constructor of Dummy class for testing
51  * \param dimension tensor dimension
52  */
53  explicit Dummy( char dimension )
54  : WValueSetBase( 0, dimension, W_DT_INT8 )
55  {
56  }
57 
58  /**
59  * Destructor.
60  */
61  virtual ~Dummy()
62  {
63  }
64 
65  /**
66  * Get the size.
67  *
68  * \return The size.
69  */
70  virtual size_t size() const
71  {
72  return 255;
73  }
74 
75  /**
76  * Get the raw size.
77  *
78  * \return The raw size.
79  */
80  virtual size_t rawSize() const
81  {
82  return 255;
83  }
84 
85  /**
86  * Get the value.
87  *
88  * \return The value at position i.
89  */
90  virtual double getScalarDouble( size_t /* i */ ) const
91  {
92  return 255;
93  }
94 
95  /**
96  * \return The i-th WValue stored in this value set. There are size() such scalars.
97  */
98  virtual WValue< double > getWValueDouble( size_t /*i*/ ) const
99  {
100  return WValue< double >( size() );
101  }
102 
103  /**
104  * This method returns the smallest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
105  * smallest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
106  *
107  * \return the smallest value in the data.
108  */
109  virtual double getMinimumValue() const
110  {
111  return 0.0;
112  }
113 
114  /**
115  * This method returns the largest value in the valueset. It does not handle vectors, matrices and so on well. It simply returns the
116  * largest value in the data array. This is especially useful for texture scaling or other statistic tools (histograms).
117  *
118  * \return the largest value in the data.
119  */
120  virtual double getMaximumValue() const
121  {
122  return 255.0;
123  }
124 };
125 
126 /**
127  * Testing abstract class via a Dummy class derived esp. for this purpose.
128  */
129 class WValueSetBaseTest : public CxxTest::TestSuite
130 {
131 public:
132  /**
133  * Checks if the Dummy is instanceable.
134  */
135  void testInstantiation( void )
136  {
137  Dummy d;
138  }
139 
140  /**
141  * Checks if the dimension using the dummy is right
142  */
143  void testDimension( void )
144  {
145  Dummy d1;
146  TS_ASSERT_EQUALS( d1.dimension(), 1 );
147  Dummy d2( 2 );
148  TS_ASSERT_EQUALS( d2.dimension(), 2 );
149  }
150  /**
151  * Checks if the dimension using the dummy is right
152  */
153  void testDataType( void )
154  {
155  Dummy d1;
156  TS_ASSERT_EQUALS( d1.getDataType(), W_DT_INT8 );
157  }
158 };
159 
160 #endif // WVALUESETBASE_TEST_H