/[escript]/branches/RW_WIN32/escript/test/DataAlgorithmAdapterTestCase.cpp
ViewVC logotype

Diff of /branches/RW_WIN32/escript/test/DataAlgorithmAdapterTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 108 by jgs, Thu Jan 27 06:21:59 2005 UTC revision 113 by jgs, Mon Feb 28 07:06:33 2005 UTC
# Line 12  Line 12 
12   *                                                                           *   *                                                                           *
13   *****************************************************************************   *****************************************************************************
14  */  */
15    
16    #include "escript/Data/DataExpanded.h"
17    #include "escript/Data/DataArrayView.h"
18  #include "escript/Data/DataAlgorithm.h"  #include "escript/Data/DataAlgorithm.h"
19  #include "DataAlgorithmAdapterTestCase.h"  #include "DataAlgorithmAdapterTestCase.h"
20    
# Line 136  void DataAlgorithmAdapterTestCase::testA Line 139  void DataAlgorithmAdapterTestCase::testA
139    
140  }  }
141    
142    void DataAlgorithmAdapterTestCase::testAlgorithm() {
143    
144      {
145        cout << endl;
146        cout << "\tTest algorithm on Data objects with a single data-point.";
147    
148        // define the shape for the DataArrayView
149        DataArrayView::ShapeType shape;
150        shape.push_back(2);
151        shape.push_back(3);
152    
153        // allocate the data for the DataArrayView
154        DataArrayView::ValueType dataArray(DataArrayView::noValues(shape),0);
155    
156        // construct DataArrayView
157        DataArrayView dataView(dataArray,shape);
158    
159        // assign values to the data point
160        for (int i=0;i<shape[0];i++) {
161          for (int j=0;j<shape[1];j++) {
162            dataView(i,j)=dataView.index(i,j);
163          }
164        }
165    
166        // create a few Data objects from the created DataArrayView
167        DataExpanded dataExp(dataView,FunctionSpace());
168        DataConstant dataCon(dataView,FunctionSpace());
169        DataTagged   dataTag(dataCon);
170    
171        // test algorithm on DataExpanded
172        assert(escript::algorithm(dataExp,DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()))==0);
173        assert(escript::algorithm(dataExp,DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1))==5);
174    
175        // test algorithm on DataTagged
176        assert(escript::algorithm(dataTag,DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()))==0);
177        assert(escript::algorithm(dataTag,DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1))==5);
178    
179        // test algorithm on DataConstant
180        assert(escript::algorithm(dataCon,DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()))==0);
181        assert(escript::algorithm(dataCon,DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1))==5);
182    
183      }
184    
185      cout << endl;
186    
187    }
188    
189    void DataAlgorithmAdapterTestCase::testDpAlgorithm() {
190    
191      {
192        cout << endl;
193        cout << "\tTest dp_algorithm on Data objects with a single data-point.";
194    
195        // define the shapes for the DataArrayViews
196        DataArrayView::ShapeType shape;
197        shape.push_back(2);
198        shape.push_back(3);
199        DataArrayView::ShapeType shape2;
200    
201        // allocate the data for the DataArrayViews
202        DataArrayView::ValueType dataArray(DataArrayView::noValues(shape),0);
203        DataArrayView::ValueType dataArray2(DataArrayView::noValues(shape2),0);
204    
205        // construct DataArrayViews
206        DataArrayView dataView(dataArray,shape);
207        DataArrayView dataView2(dataArray2,shape2);
208    
209        // assign values to the data point
210        for (int i=0;i<shape[0];i++) {
211          for (int j=0;j<shape[1];j++) {
212            dataView(i,j)=dataView.index(i,j);
213          }
214        }
215    
216        // create a few Data objects from the created DataArrayViews
217        DataExpanded dataExp(dataView,FunctionSpace());
218        DataConstant dataCon(dataView,FunctionSpace());
219        DataTagged   dataTag(dataCon);
220    
221        // and create Data objects to receive the results of the dp_algorithm calls
222        DataExpanded dataExp2(dataView2,FunctionSpace());
223        DataConstant dataCon2(dataView2,FunctionSpace());
224        DataTagged   dataTag2(dataCon2);
225    
226        // test dp_algorithm on DataExpanded
227        escript::dp_algorithm(dataExp,dataExp2,DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));
228        assert(dataExp2.getDataPoint(0,0)()==0);
229        escript::dp_algorithm(dataExp,dataExp2,DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));
230        assert(dataExp2.getDataPoint(0,0)()==5);
231    
232        // test dp_algorithm on DataTagged
233        escript::dp_algorithm(dataTag,dataTag2,DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));
234        assert(dataTag2.getDataPoint(0,0)()==0);
235        escript::dp_algorithm(dataTag,dataTag2,DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));
236        assert(dataTag2.getDataPoint(0,0)()==5);
237    
238        // test dp_algorithm on DataConstant
239        escript::dp_algorithm(dataCon,dataCon2,DataAlgorithmAdapter<FMin>(numeric_limits<double>::max()));
240        assert(dataCon2.getDataPoint(0,0)()==0);
241        escript::dp_algorithm(dataCon,dataCon2,DataAlgorithmAdapter<FMax>(numeric_limits<double>::max()*-1));
242        assert(dataCon2.getDataPoint(0,0)()==5);
243    
244      }
245    
246      cout << endl;
247    
248    }
249    
250  TestSuite* DataAlgorithmAdapterTestCase::suite ()  TestSuite* DataAlgorithmAdapterTestCase::suite ()
251  {  {
252    //    //
# Line 143  TestSuite* DataAlgorithmAdapterTestCase: Line 254  TestSuite* DataAlgorithmAdapterTestCase:
254    TestSuite *testSuite = new TestSuite ("DataAlgorithmAdapterTestCase");    TestSuite *testSuite = new TestSuite ("DataAlgorithmAdapterTestCase");
255    
256    testSuite->addTest (new TestCaller< DataAlgorithmAdapterTestCase>("testAll",&DataAlgorithmAdapterTestCase::testAll));    testSuite->addTest (new TestCaller< DataAlgorithmAdapterTestCase>("testAll",&DataAlgorithmAdapterTestCase::testAll));
257      testSuite->addTest (new TestCaller<DataAlgorithmAdapterTestCase>("testAlgorithm",&DataAlgorithmAdapterTestCase::testAlgorithm));
258      testSuite->addTest (new TestCaller<DataAlgorithmAdapterTestCase>("testDpAlgorithm",&DataAlgorithmAdapterTestCase::testDpAlgorithm));
259    return testSuite;    return testSuite;
260  }  }
261    

Legend:
Removed from v.108  
changed lines
  Added in v.113

  ViewVC Help
Powered by ViewVC 1.1.26