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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 622 - (hide annotations)
Wed Mar 22 14:00:08 2006 UTC (13 years, 7 months ago) by robwdcock
Original Path: branches/ROBW_XPLATFORM/escript/test/DataBlocks2D/DataBlocks2DTestCase.cpp
File size: 5984 byte(s)
Creating a private branch so I can test and verify cross-platform build
1 jgs 82 // $Id$
2     /*
3     *****************************************************************************
4     * *
5     * COPYRIGHT ACcESS - All Rights Reserved *
6     * *
7     * This software is the property of ACcESS. No part of this code *
8     * may be copied in any form or by any means without the expressed written *
9     * consent of ACcESS. Copying, use or modification of this software *
10     * by any unauthorised person is illegal unless that person has a software *
11     * license agreement with ACcESS. *
12     * *
13     *****************************************************************************
14     */
15 jgs 117
16 jgs 474 #include "DataBlocks2D.h"
17 jgs 468 #include "EsysException.h"
18 jgs 82
19     #include "DataBlocks2DTestCase.h"
20    
21     #include <iostream>
22    
23     using namespace std;
24     using namespace CppUnitTest;
25     using namespace escript;
26     using namespace esysUtils;
27    
28     void DataBlocks2DTestCase::setUp() {
29     //
30     // This is called before each test is run
31    
32     }
33    
34     void DataBlocks2DTestCase::tearDown() {
35     //
36     // This is called after each test has been run
37    
38     }
39    
40     void DataBlocks2DTestCase::testAll() {
41    
42     cout << endl;
43    
44 jgs 117 cout << "\tTest DataBlocks2D constructor for various dimension values:" << endl;
45 jgs 82
46     {
47     cout << "\t\tnumRows = 1, numCols = 1, blockSize = 20." << endl;
48     int numRows=1;
49     int numCols=1;
50     int blockSize=20;
51     DataBlocks2D myData(numRows,numCols,blockSize);
52 jgs 117 int i = numRows-1;
53     int j = numCols-1;
54     assert(myData.index(i,j) == (i*numCols+j)*blockSize);
55     assert(myData.size() == numRows*numCols*blockSize);
56 jgs 82 }
57    
58     {
59     cout << "\t\tnumRows = 3, numCols = 5, blockSize = 20." << endl;
60     int numRows=3;
61     int numCols=5;
62     int blockSize=20;
63     DataBlocks2D myData(numRows,numCols,blockSize);
64 jgs 117 int i = numRows-1;
65     int j = numCols-1;
66     assert(myData.index(i,j) == (i*numCols+j)*blockSize);
67     assert(myData.size() == numRows*numCols*blockSize);
68 jgs 82 }
69    
70     {
71     cout << "\t\tnumRows = 3, numCols = 5, blockSize = 1." << endl;
72     int numRows=3;
73     int numCols=5;
74     int blockSize=1;
75     DataBlocks2D myData(numRows,numCols,blockSize);
76 jgs 117 int i = numRows-1;
77     int j = numCols-1;
78     assert(myData.index(i,j) == (i*numCols+j)*blockSize);
79     assert(myData.size() == numRows*numCols*blockSize);
80 jgs 82 }
81    
82     {
83     cout << "\t\tnumRows = 1, numCols = 1, blockSize = 1." << endl;
84     int numRows=1;
85     int numCols=1;
86     int blockSize=1;
87     DataBlocks2D myData(numRows,numCols,blockSize);
88 jgs 117 int i = numRows-1;
89     int j = numCols-1;
90     assert(myData.index(i,j) == (i*numCols+j)*blockSize);
91     assert(myData.size() == numRows*numCols*blockSize);
92 jgs 82 }
93    
94     {
95 jgs 117 cout << "\tTest DataBlocks2D.index and DataBlocks2D operator[] for blockSize = 3." << endl;
96 jgs 82 int numRows=10;
97     int numCols=8;
98     int blockSize=3;
99     DataBlocks2D myData(numRows,numCols,blockSize);
100 jgs 117 int val=0;
101     for (int i=0; i<numRows; i++) {
102     for (int j=0; j<numCols; j++) {
103     for (int k=0; k<blockSize; k++) {
104     myData[myData.index(i,j)+k] = val;
105     val++;
106     }
107 jgs 82 }
108     }
109 jgs 117 val=0;
110     for (int i=0; i<numRows; i++) {
111     for (int j=0; j<numCols; j++) {
112     for (int k=0; k<blockSize; k++) {
113     assert(myData[myData.index(i,j)+k] == val);
114     val++;
115     }
116     }
117     }
118 jgs 82 }
119    
120     {
121 jgs 151 cout << "\tTest DataBlocks2D exception for numRows = 0." << endl;
122     int numRows=0;
123     int numCols=8;
124     int blockSize=10;
125     try {
126     DataBlocks2D myData(numRows,numCols,blockSize);
127     assert(false);
128     }
129     catch(EsysException& e) {
130     assert(true);
131     }
132     }
133    
134     {
135     cout << "\tTest DataBlocks2D exception for numCols = 0." << endl;
136 jgs 82 int numRows=10;
137 jgs 151 int numCols=0;
138     int blockSize=10;
139     try {
140     DataBlocks2D myData(numRows,numCols,blockSize);
141     assert(false);
142     }
143     catch(EsysException& e) {
144     assert(true);
145     }
146     }
147    
148     {
149     cout << "\tTest DataBlocks2D exception for blockSize = 0." << endl;
150     int numRows=10;
151 jgs 82 int numCols=8;
152     int blockSize=0;
153 jgs 151 try {
154     DataBlocks2D myData(numRows,numCols,blockSize);
155     assert(false);
156 jgs 82 }
157 jgs 151 catch(EsysException& e) {
158     assert(true);
159     }
160 jgs 82 }
161    
162     {
163 jgs 117 cout << "\tTest getNumRows, getNumCols and getBlockSize." << endl;
164 jgs 82 int numRows=1;
165     int numCols=1;
166     int blockSize=1;
167     DataBlocks2D myData(numRows,numCols,blockSize);
168     assert(myData.getNumRows() == numRows);
169     assert(myData.getNumCols() == numCols);
170 jgs 117 assert(myData.getBlockSize() == blockSize);
171 jgs 82 }
172    
173     {
174     cout << "\tTest resize." << endl;
175     int numRows=1;
176     int numCols=1;
177     int blockSize=1;
178     DataBlocks2D myData;
179     myData.resize(numRows,numCols,blockSize);
180     assert(myData.getNumRows() == numRows);
181     assert(myData.getNumCols() == numCols);
182 jgs 117 assert(myData.getBlockSize() == blockSize);
183 jgs 82 }
184    
185     {
186     cout << "\tTest = operator, swap, and copy constructor." << endl;
187     DataBlocks2D myData1;
188     DataBlocks2D myData2(1, 1, 1);
189 jgs 117 int val=0;
190     for (int i=0; i<1; i++) {
191     for (int j=0; j<1; j++) {
192     for (int k=0; k<1; k++) {
193     myData2[myData2.index(i,j)+k] = val;
194     val++;
195     }
196     }
197     }
198 jgs 82 myData1 = myData2;
199 jgs 117 for (int i=0; i<myData1.getNumRows(); i++) {
200     for (int j=0; j<myData1.getNumCols(); j++) {
201     assert(myData1(i,j) == myData2(i,j));
202     }
203     }
204 jgs 82 }
205    
206 jgs 117 {
207     cout << "\tTest DOASSERT exception." << endl;
208     DataBlocks2D myData;
209     try {
210     myData.index(1,2);
211     assert(false);
212     }
213     catch (EsysException& e) {
214     assert(true);
215     }
216     }
217    
218 jgs 82 }
219    
220     TestSuite* DataBlocks2DTestCase::suite ()
221     {
222     //
223     // create the suite of tests to perform.
224     TestSuite *testSuite = new TestSuite ("DataBlocks2DTestCase");
225    
226     testSuite->addTest (new TestCaller< DataBlocks2DTestCase>("testAll",&DataBlocks2DTestCase::testAll));
227     return testSuite;
228     }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26