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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1388 - (hide annotations)
Fri Jan 11 07:45:58 2008 UTC (11 years, 10 months ago) by trankine
File size: 5589 byte(s)
And get the *(&(*&(* name right
1 jgs 117
2 ksteube 1312 /* $Id$ */
3    
4     /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16 robwdcock 670 #include "escript/DataBlocks2D.h"
17 robwdcock 638 #include "esysUtils/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 gross 710 #if defined DOASSERT
207 jgs 117 {
208     cout << "\tTest DOASSERT exception." << endl;
209     DataBlocks2D myData;
210     try {
211     myData.index(1,2);
212     assert(false);
213     }
214     catch (EsysException& e) {
215     assert(true);
216     }
217     }
218 gross 710 #endif
219 jgs 117
220 jgs 82 }
221    
222     TestSuite* DataBlocks2DTestCase::suite ()
223     {
224     //
225     // create the suite of tests to perform.
226     TestSuite *testSuite = new TestSuite ("DataBlocks2DTestCase");
227    
228     testSuite->addTest (new TestCaller< DataBlocks2DTestCase>("testAll",&DataBlocks2DTestCase::testAll));
229     return testSuite;
230     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26