/[escript]/trunk/escript/test/DataLazyTestCase.cpp
ViewVC logotype

Diff of /trunk/escript/test/DataLazyTestCase.cpp

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

revision 2084 by jfenwick, Thu Nov 20 05:31:33 2008 UTC revision 2085 by jfenwick, Mon Nov 24 00:45:48 2008 UTC
# Line 96  getLazyU(DataTypes::ShapeType& shape, ES Line 96  getLazyU(DataTypes::ShapeType& shape, ES
96    return DataAbstract_ptr(l);    return DataAbstract_ptr(l);
97  }  }
98    
99    DataAbstract_ptr
100    getLazyUP(DataTypes::ShapeType& shape, ES_optype typ, int par)
101    {
102      int pts=DataTypes::noValues(shape);
103      DataTypes::ValueType data(pts,0);
104      for (int i=0;i<pts;++i)
105      {
106        data[i]=(i+1);
107      }
108      DataConstant* p=new DataConstant(FunctionSpace(),shape,data);
109      DataAbstract_ptr pp(p);
110      DataLazy* l=new DataLazy(pp,typ,par);
111      return DataAbstract_ptr(l);
112    }
113    
114    
115  DataAbstract_ptr  DataAbstract_ptr
116  getLazyB(DataTypes::ShapeType& shape, ES_optype typ)  getLazyB(DataTypes::ShapeType& shape, ES_optype typ)
# Line 116  getLazyB(DataTypes::ShapeType& shape, ES Line 131  getLazyB(DataTypes::ShapeType& shape, ES
131    return DataAbstract_ptr(l);    return DataAbstract_ptr(l);
132  }  }
133    
134    DataAbstract_ptr
135    getLazyGTP(DataTypes::ShapeType& shape, ES_optype typ, int ax, int tr)
136    {
137      int pts=DataTypes::noValues(shape);
138      DataTypes::ValueType data(pts,0);
139      DataTypes::ValueType data2(pts,0);
140      for (int i=0;i<pts;++i)
141      {
142        data[i]=(i+1);
143        data2[i]=-(i+1);
144      }
145      DataConstant* p=new DataConstant(FunctionSpace(),shape,data);
146      DataConstant* p2=new DataConstant(FunctionSpace(),shape,data2);
147      DataAbstract_ptr pp(p);
148      DataAbstract_ptr pp2(p2);
149      DataLazy* l=new DataLazy(pp,pp2,typ,ax,tr);
150      return DataAbstract_ptr(l);
151    }
152    
153    
154    
155  #define TESTOP(X,V) { DataAbstract_ptr d1=getLazy(shape); assert(d1->X()==V); assert(d1->isLazy());}  #define TESTOP(X,V) { DataAbstract_ptr d1=getLazy(shape); assert(d1->X()==V); assert(d1->isLazy());}
156    
157  }  }
# Line 173  void DataLazyTestCase::testLazy2() Line 209  void DataLazyTestCase::testLazy2()
209    }    }
210  }  }
211    
212  #define TESTOPB(X,V,O) { DataAbstract_ptr d1=getLazyB(shape,O); assert(dynamic_pointer_cast<DataLazy>(d1)->X()==V); assert(dynamic_pointer_cast<DataLazy>(d1)->isLazy());}  #define TESTOPUP(X,V,O) { DataAbstract_ptr d1=getLazyUP(shape,O,0); assert(dynamic_pointer_cast<DataLazy>(d1)->X()==V); assert(d1->isLazy());}
213  // This method tests the unary op  constructor  // This method tests the unary op  constructor
214  // We aren't checking the correctness of the results here, just that they have the right properties  // We aren't checking the correctness of the results here, just that they have the right properties
215    void DataLazyTestCase::testLazy2p()
216    {
217      cout << endl;
218      cout << "\tTesting UNARY (with arg) constructor (basic checks only)\n";
219    
220      DataTypes::ShapeType shape;
221      DataAbstract_ptr d1=getLazyUP(shape,TRANS,0);
222      assert(d1->isLazy());
223    
224      for (int j=TRANS;j<=TRACE;++j)
225      {
226        shape=DataTypes::scalarShape;
227        ES_optype op=(ES_optype)(j);            // not even reinterpret_cast works here
228                        // if other compilers object I'll write a switch
229        cout << "\t" << opToString(op) << endl;
230        for (int i=0;i<5;++i)
231        {
232        if (op==TRACE)
233        {
234           TESTOPUP(getRank,0,op);
235               TESTOPUP(getNoValues,1,op);
236               TESTOPUP(getShape,DataTypes::scalarShape,op);
237        }
238        else
239        {
240           TESTOPUP(getRank,i,op);
241               TESTOPUP(getNoValues,DataTypes::noValues(shape),op);
242               TESTOPUP(getShape,shape,op);
243    
244        }
245            TESTOPUP(getNumDPPSample,1,op);
246            TESTOPUP(getNumSamples,1,op);
247        TESTOPUP(getBuffsRequired,2,op);
248            shape.push_back(3);
249        }
250      }
251    }
252    
253    #define TESTOPB(X,V,O) { DataAbstract_ptr d1=getLazyB(shape,O); assert(dynamic_pointer_cast<DataLazy>(d1)->X()==V); assert(dynamic_pointer_cast<DataLazy>(d1)->isLazy());}
254    // This method tests the binary op  constructor
255    // We aren't checking the correctness of the results here, just that they have the right properties
256  void DataLazyTestCase::testLazy3()  void DataLazyTestCase::testLazy3()
257  {  {
258    cout << endl;    cout << endl;
# Line 204  void DataLazyTestCase::testLazy3() Line 281  void DataLazyTestCase::testLazy3()
281    }    }
282  }  }
283    
284    
285    
286    
287    #define TESTOPGTP(X,V,O) { DataAbstract_ptr d1=getLazyGTP(shape,O,0,0); assert(dynamic_pointer_cast<DataLazy>(d1)->X()==V); assert(dynamic_pointer_cast<DataLazy>(d1)->isLazy());}
288    
289    // This method tests the GeneralTensorproduct  constructor
290    // We aren't checking the correctness of the results here, just that they have the right properties
291    void DataLazyTestCase::testLazy4()
292    {
293      cout << endl;
294      cout << "\tTesting GTP constructor (basic checks only)\n";
295    
296      DataTypes::ShapeType shape;
297      DataTypes::ShapeType prodshape;
298    
299      DataAbstract_ptr d1=getLazyGTP(shape,PROD,0,0);
300      assert(d1->isLazy());
301    
302      for (int j=PROD;j<=PROD;++j)
303      {
304        shape=DataTypes::scalarShape;
305        ES_optype op=(ES_optype)(j);            // not even reinterpret_cast works here
306                        // if other compilers object I'll write a switch
307        cout << "\t" << opToString(op) << endl;
308        for (int i=0;i<3;++i)
309        {
310        ShapeType ns;
311        for (int k=0;k<i;++k)
312        {
313          ns.push_back(3);
314          ns.push_back(3);
315        }
316        TESTOPGTP(getRank,i*2,op);
317            TESTOPGTP(getNoValues,DataTypes::noValues(ns),op);
318            TESTOPGTP(getShape,ns,op);
319            TESTOPGTP(getNumDPPSample,1,op);
320            TESTOPGTP(getNumSamples,1,op);
321        TESTOPGTP(getBuffsRequired,3,op);
322            shape.push_back(3);
323        }
324      }
325    }
326    
327    
328    
329  void DataLazyTestCase::testBuffers()  void DataLazyTestCase::testBuffers()
330  {  {
331    cout << endl;    cout << endl;
# Line 216  void DataLazyTestCase::testBuffers() Line 338  void DataLazyTestCase::testBuffers()
338    assert(dynamic_pointer_cast<DataLazy>(p4)->getBuffsRequired()==2);    assert(dynamic_pointer_cast<DataLazy>(p4)->getBuffsRequired()==2);
339    DataAbstract_ptr p5=(new DataLazy(p2,p4,ADD))->getPtr();    DataAbstract_ptr p5=(new DataLazy(p2,p4,ADD))->getPtr();
340    assert(dynamic_pointer_cast<DataLazy>(p5)->getBuffsRequired()==3);    assert(dynamic_pointer_cast<DataLazy>(p5)->getBuffsRequired()==3);
341      DataAbstract_ptr p6=(new DataLazy(p5,TRANS,0))->getPtr();
342      assert(dynamic_pointer_cast<DataLazy>(p6)->getBuffsRequired()==4);
343      DataAbstract_ptr p7=(new DataLazy(p6,p6,PROD,0,0))->getPtr();
344      assert(dynamic_pointer_cast<DataLazy>(p7)->getBuffsRequired()==6);
345      DataAbstract_ptr p8=(new DataLazy(p7,TRACE,0))->getPtr();
346      assert(dynamic_pointer_cast<DataLazy>(p8)->getBuffsRequired()==7);
347  }  }
348    
349    
# Line 227  TestSuite* DataLazyTestCase::suite () Line 355  TestSuite* DataLazyTestCase::suite ()
355    
356    testSuite->addTest (new TestCaller< DataLazyTestCase>("Identity",&DataLazyTestCase::testLazy1));    testSuite->addTest (new TestCaller< DataLazyTestCase>("Identity",&DataLazyTestCase::testLazy1));
357    testSuite->addTest (new TestCaller< DataLazyTestCase>("Unary",&DataLazyTestCase::testLazy2));    testSuite->addTest (new TestCaller< DataLazyTestCase>("Unary",&DataLazyTestCase::testLazy2));
358      testSuite->addTest (new TestCaller< DataLazyTestCase>("Unary (params)",&DataLazyTestCase::testLazy2p));
359    testSuite->addTest (new TestCaller< DataLazyTestCase>("Binary",&DataLazyTestCase::testLazy3));    testSuite->addTest (new TestCaller< DataLazyTestCase>("Binary",&DataLazyTestCase::testLazy3));
360      testSuite->addTest (new TestCaller< DataLazyTestCase>("GTP",&DataLazyTestCase::testLazy4));
361    testSuite->addTest (new TestCaller< DataLazyTestCase>("Buffers",&DataLazyTestCase::testBuffers));    testSuite->addTest (new TestCaller< DataLazyTestCase>("Buffers",&DataLazyTestCase::testBuffers));
362    return testSuite;    return testSuite;
363  }  }

Legend:
Removed from v.2084  
changed lines
  Added in v.2085

  ViewVC Help
Powered by ViewVC 1.1.26