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

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

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

revision 3596 by jfenwick, Thu Jan 28 02:03:15 2010 UTC revision 3597 by caltinay, Thu Sep 15 06:03:17 2011 UTC
# Line 12  Line 12 
12  *******************************************************/  *******************************************************/
13    
14    
15    #include "DataBlocks2DTestCase.h"
16  #include "escript/DataBlocks2D.h"  #include "escript/DataBlocks2D.h"
17  #include "esysUtils/EsysException.h"  #include "esysUtils/EsysException.h"
18    
19  #include "DataBlocks2DTestCase.h"  #include <cppunit/TestCaller.h>
   
20  #include <iostream>  #include <iostream>
21    
22  using namespace std;  using namespace std;
23  using namespace CppUnitTest;  using namespace CppUnit;
24  using namespace escript;  using namespace escript;
25  using namespace esysUtils;  using namespace esysUtils;
26    
27  void DataBlocks2DTestCase::setUp() {  void DataBlocks2DTestCase::testAll()
28    //  {
   // This is called before each test is run  
   
 }  
   
 void DataBlocks2DTestCase::tearDown() {  
   //  
   // This is called after each test has been run  
   
 }  
   
 void DataBlocks2DTestCase::testAll() {  
   
29    cout << endl;    cout << endl;
   
30    cout << "\tTest DataBlocks2D constructor for various dimension values:" << endl;    cout << "\tTest DataBlocks2D constructor for various dimension values:" << endl;
31    
32    {    {
# Line 50  void DataBlocks2DTestCase::testAll() { Line 37  void DataBlocks2DTestCase::testAll() {
37      DataBlocks2D myData(numRows,numCols,blockSize);      DataBlocks2D myData(numRows,numCols,blockSize);
38      int i = numRows-1;      int i = numRows-1;
39      int j = numCols-1;      int j = numCols-1;
40      assert(myData.index(i,j) == (i*numCols+j)*blockSize);      CPPUNIT_ASSERT(myData.index(i,j) == (i*numCols+j)*blockSize);
41      assert(myData.size() == numRows*numCols*blockSize);      CPPUNIT_ASSERT(myData.size() == numRows*numCols*blockSize);
42    }    }
43    
44    {    {
# Line 62  void DataBlocks2DTestCase::testAll() { Line 49  void DataBlocks2DTestCase::testAll() {
49      DataBlocks2D myData(numRows,numCols,blockSize);      DataBlocks2D myData(numRows,numCols,blockSize);
50      int i = numRows-1;      int i = numRows-1;
51      int j = numCols-1;      int j = numCols-1;
52      assert(myData.index(i,j) == (i*numCols+j)*blockSize);      CPPUNIT_ASSERT(myData.index(i,j) == (i*numCols+j)*blockSize);
53      assert(myData.size() == numRows*numCols*blockSize);      CPPUNIT_ASSERT(myData.size() == numRows*numCols*blockSize);
54    }    }
55    
56    {    {
# Line 74  void DataBlocks2DTestCase::testAll() { Line 61  void DataBlocks2DTestCase::testAll() {
61      DataBlocks2D myData(numRows,numCols,blockSize);      DataBlocks2D myData(numRows,numCols,blockSize);
62      int i = numRows-1;      int i = numRows-1;
63      int j = numCols-1;      int j = numCols-1;
64      assert(myData.index(i,j) == (i*numCols+j)*blockSize);      CPPUNIT_ASSERT(myData.index(i,j) == (i*numCols+j)*blockSize);
65      assert(myData.size() == numRows*numCols*blockSize);      CPPUNIT_ASSERT(myData.size() == numRows*numCols*blockSize);
66    }    }
67    
68    {    {
# Line 86  void DataBlocks2DTestCase::testAll() { Line 73  void DataBlocks2DTestCase::testAll() {
73      DataBlocks2D myData(numRows,numCols,blockSize);      DataBlocks2D myData(numRows,numCols,blockSize);
74      int i = numRows-1;      int i = numRows-1;
75      int j = numCols-1;      int j = numCols-1;
76      assert(myData.index(i,j) == (i*numCols+j)*blockSize);      CPPUNIT_ASSERT(myData.index(i,j) == (i*numCols+j)*blockSize);
77      assert(myData.size() == numRows*numCols*blockSize);      CPPUNIT_ASSERT(myData.size() == numRows*numCols*blockSize);
78    }    }
79    
80    {    {
# Line 109  void DataBlocks2DTestCase::testAll() { Line 96  void DataBlocks2DTestCase::testAll() {
96      for (int i=0; i<numRows; i++) {      for (int i=0; i<numRows; i++) {
97        for (int j=0; j<numCols; j++) {        for (int j=0; j<numCols; j++) {
98          for (int k=0; k<blockSize; k++) {          for (int k=0; k<blockSize; k++) {
99        assert(myData[myData.index(i,j)+k] == val);        CPPUNIT_ASSERT(myData[myData.index(i,j)+k] == val);
100            val++;            val++;
101          }          }
102        }        }
# Line 123  void DataBlocks2DTestCase::testAll() { Line 110  void DataBlocks2DTestCase::testAll() {
110      int blockSize=10;      int blockSize=10;
111      try {      try {
112          DataBlocks2D myData(numRows,numCols,blockSize);          DataBlocks2D myData(numRows,numCols,blockSize);
113          assert(false);          CPPUNIT_FAIL("Exception not thrown");
114      }      }
115      catch(EsysException&) {      catch(EsysException&) {
116          assert(true);          CPPUNIT_ASSERT(true);
117      }      }
118    }    }
119    
# Line 137  void DataBlocks2DTestCase::testAll() { Line 124  void DataBlocks2DTestCase::testAll() {
124      int blockSize=10;      int blockSize=10;
125      try {      try {
126          DataBlocks2D myData(numRows,numCols,blockSize);          DataBlocks2D myData(numRows,numCols,blockSize);
127          assert(false);          CPPUNIT_FAIL("Exception not thrown");
128      }      }
129      catch(EsysException&) {      catch(EsysException&) {
130          assert(true);          CPPUNIT_ASSERT(true);
131      }      }
132    }    }
133    
# Line 151  void DataBlocks2DTestCase::testAll() { Line 138  void DataBlocks2DTestCase::testAll() {
138      int blockSize=0;      int blockSize=0;
139      try {      try {
140          DataBlocks2D myData(numRows,numCols,blockSize);          DataBlocks2D myData(numRows,numCols,blockSize);
141          assert(false);          CPPUNIT_FAIL("Exception not thrown");
142      }      }
143      catch(EsysException&) {      catch(EsysException&) {
144          assert(true);          CPPUNIT_ASSERT(true);
145      }      }
146    }    }
147    
# Line 164  void DataBlocks2DTestCase::testAll() { Line 151  void DataBlocks2DTestCase::testAll() {
151      int numCols=1;      int numCols=1;
152      int blockSize=1;      int blockSize=1;
153      DataBlocks2D myData(numRows,numCols,blockSize);      DataBlocks2D myData(numRows,numCols,blockSize);
154      assert(myData.getNumRows() == numRows);      CPPUNIT_ASSERT(myData.getNumRows() == numRows);
155      assert(myData.getNumCols() == numCols);      CPPUNIT_ASSERT(myData.getNumCols() == numCols);
156      assert(myData.getBlockSize() == blockSize);      CPPUNIT_ASSERT(myData.getBlockSize() == blockSize);
157    }    }
158    
159    {    {
# Line 176  void DataBlocks2DTestCase::testAll() { Line 163  void DataBlocks2DTestCase::testAll() {
163      int blockSize=1;      int blockSize=1;
164      DataBlocks2D myData;      DataBlocks2D myData;
165      myData.resize(numRows,numCols,blockSize);      myData.resize(numRows,numCols,blockSize);
166      assert(myData.getNumRows() == numRows);      CPPUNIT_ASSERT(myData.getNumRows() == numRows);
167      assert(myData.getNumCols() == numCols);      CPPUNIT_ASSERT(myData.getNumCols() == numCols);
168      assert(myData.getBlockSize() == blockSize);      CPPUNIT_ASSERT(myData.getBlockSize() == blockSize);
169    }    }
170    
171    {    {
# Line 197  void DataBlocks2DTestCase::testAll() { Line 184  void DataBlocks2DTestCase::testAll() {
184      myData1 = myData2;      myData1 = myData2;
185      for (int i=0; i<myData1.getNumRows(); i++) {      for (int i=0; i<myData1.getNumRows(); i++) {
186        for (int j=0; j<myData1.getNumCols(); j++) {        for (int j=0; j<myData1.getNumCols(); j++) {
187      assert(myData1(i,j) == myData2(i,j));      CPPUNIT_ASSERT(myData1(i,j) == myData2(i,j));
188        }        }
189      }      }
190    }    }
191    
192    #if defined DOASSERT  #if defined DOASSERT
193    {    {
194      cout << "\tTest DOASSERT exception." << endl;      cout << "\tTest DOASSERT exception." << endl;
195      DataBlocks2D myData;      DataBlocks2D myData;
196      try {      CPPUNIT_ASSERT_THROW(myData.index(1,2), EsysException);
       myData.index(1,2);  
       assert(false);  
     }  
     catch (EsysException&) {  
       assert(true);  
     }  
197    }    }
198    #endif  #endif
   
199  }  }
200    
201  TestSuite* DataBlocks2DTestCase::suite ()  TestSuite* DataBlocks2DTestCase::suite()
202  {  {
203    //    TestSuite *testSuite = new TestSuite("DataBlocks2DTestCase");
   // create the suite of tests to perform.  
   TestSuite *testSuite = new TestSuite ("DataBlocks2DTestCase");  
204    
205    testSuite->addTest (new TestCaller< DataBlocks2DTestCase>("testAll",&DataBlocks2DTestCase::testAll));    testSuite->addTest(new TestCaller<DataBlocks2DTestCase>(
206                  "testAll",&DataBlocks2DTestCase::testAll));
207    return testSuite;    return testSuite;
208  }  }
209    

Legend:
Removed from v.3596  
changed lines
  Added in v.3597

  ViewVC Help
Powered by ViewVC 1.1.26