/[escript]/trunk/escript/test/DataAlgorithmAdapter/DataAlgorithmAdapterTestCase.cpp
ViewVC logotype

Diff of /trunk/escript/test/DataAlgorithmAdapter/DataAlgorithmAdapterTestCase.cpp

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

trunk/esys2/escript/test/DataAlgorithmAdapter/DataAlgorithmAdapterTestCase.cpp revision 108 by jgs, Thu Jan 27 06:21:59 2005 UTC trunk/escript/test/DataAlgorithmAdapter/DataAlgorithmAdapterTestCase.cpp revision 155 by jgs, Wed Nov 9 02:02:19 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        FMin fmin_func;
173        assert(escript::algorithm(dataExp,fmin_func,numeric_limits<double>::max())==0);
174        FMax fmax_func;
175        assert(escript::algorithm(dataExp,fmax_func,numeric_limits<double>::max()*-1)==5);
176    
177        // test algorithm on DataTagged
178        assert(escript::algorithm(dataTag,fmin_func,numeric_limits<double>::max())==0);
179        assert(escript::algorithm(dataTag,fmax_func,numeric_limits<double>::max()*-1)==5);
180    
181        // test algorithm on DataConstant
182        assert(escript::algorithm(dataCon,fmin_func,numeric_limits<double>::max())==0);
183        assert(escript::algorithm(dataCon,fmax_func,numeric_limits<double>::max()*-1)==5);
184    
185      }
186    
187      cout << endl;
188    
189    }
190    
191    void DataAlgorithmAdapterTestCase::testDpAlgorithm() {
192    
193      {
194        cout << endl;
195        cout << "\tTest dp_algorithm on Data objects with a single data-point.";
196    
197        // define the shapes for the DataArrayViews
198        DataArrayView::ShapeType shape;
199        shape.push_back(2);
200        shape.push_back(3);
201        DataArrayView::ShapeType shape2;
202    
203        // allocate the data for the DataArrayViews
204        DataArrayView::ValueType dataArray(DataArrayView::noValues(shape),0);
205        DataArrayView::ValueType dataArray2(DataArrayView::noValues(shape2),0);
206    
207        // construct DataArrayViews
208        DataArrayView dataView(dataArray,shape);
209        DataArrayView dataView2(dataArray2,shape2);
210    
211        // assign values to the data point
212        for (int i=0;i<shape[0];i++) {
213          for (int j=0;j<shape[1];j++) {
214            dataView(i,j)=dataView.index(i,j);
215          }
216        }
217    
218        // create a few Data objects from the created DataArrayViews
219        DataExpanded dataExp(dataView,FunctionSpace());
220        DataConstant dataCon(dataView,FunctionSpace());
221        DataTagged   dataTag(dataCon);
222    
223        // and create Data objects to receive the results of the dp_algorithm calls
224        DataExpanded dataExp2(dataView2,FunctionSpace());
225        DataConstant dataCon2(dataView2,FunctionSpace());
226        DataTagged   dataTag2(dataCon2);
227    
228        // test dp_algorithm on DataExpanded
229        FMin fmin_func;
230        escript::dp_algorithm(dataExp,dataExp2,fmin_func,numeric_limits<double>::max());
231        assert(dataExp2.getDataPoint(0,0)()==0);
232        FMax fmax_func;
233        escript::dp_algorithm(dataExp,dataExp2,fmax_func,numeric_limits<double>::max()*-1);
234        assert(dataExp2.getDataPoint(0,0)()==5);
235    
236        // test dp_algorithm on DataTagged
237        escript::dp_algorithm(dataTag,dataTag2,fmin_func,numeric_limits<double>::max());
238        assert(dataTag2.getDataPoint(0,0)()==0);
239        escript::dp_algorithm(dataTag,dataTag2,fmax_func,numeric_limits<double>::max()*-1);
240        assert(dataTag2.getDataPoint(0,0)()==5);
241    
242        // test dp_algorithm on DataConstant
243        escript::dp_algorithm(dataCon,dataCon2,fmin_func,numeric_limits<double>::max());
244        assert(dataCon2.getDataPoint(0,0)()==0);
245        escript::dp_algorithm(dataCon,dataCon2,fmax_func,numeric_limits<double>::max()*-1);
246        assert(dataCon2.getDataPoint(0,0)()==5);
247    
248      }
249    
250      cout << endl;
251    
252    }
253    
254  TestSuite* DataAlgorithmAdapterTestCase::suite ()  TestSuite* DataAlgorithmAdapterTestCase::suite ()
255  {  {
256    //    //
# Line 143  TestSuite* DataAlgorithmAdapterTestCase: Line 258  TestSuite* DataAlgorithmAdapterTestCase:
258    TestSuite *testSuite = new TestSuite ("DataAlgorithmAdapterTestCase");    TestSuite *testSuite = new TestSuite ("DataAlgorithmAdapterTestCase");
259    
260    testSuite->addTest (new TestCaller< DataAlgorithmAdapterTestCase>("testAll",&DataAlgorithmAdapterTestCase::testAll));    testSuite->addTest (new TestCaller< DataAlgorithmAdapterTestCase>("testAll",&DataAlgorithmAdapterTestCase::testAll));
261      testSuite->addTest (new TestCaller<DataAlgorithmAdapterTestCase>("testAlgorithm",&DataAlgorithmAdapterTestCase::testAlgorithm));
262      testSuite->addTest (new TestCaller<DataAlgorithmAdapterTestCase>("testDpAlgorithm",&DataAlgorithmAdapterTestCase::testDpAlgorithm));
263    return testSuite;    return testSuite;
264  }  }
265    

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

  ViewVC Help
Powered by ViewVC 1.1.26