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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years, 2 months ago) by ksteube
File size: 5546 byte(s)
Copyright updated in all files

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #include "escript/DataBlocks2D.h"
16 #include "esysUtils/EsysException.h"
17
18 #include "DataBlocks2DTestCase.h"
19
20 #include <iostream>
21
22 using namespace std;
23 using namespace CppUnitTest;
24 using namespace escript;
25 using namespace esysUtils;
26
27 void DataBlocks2DTestCase::setUp() {
28 //
29 // This is called before each test is run
30
31 }
32
33 void DataBlocks2DTestCase::tearDown() {
34 //
35 // This is called after each test has been run
36
37 }
38
39 void DataBlocks2DTestCase::testAll() {
40
41 cout << endl;
42
43 cout << "\tTest DataBlocks2D constructor for various dimension values:" << endl;
44
45 {
46 cout << "\t\tnumRows = 1, numCols = 1, blockSize = 20." << endl;
47 int numRows=1;
48 int numCols=1;
49 int blockSize=20;
50 DataBlocks2D myData(numRows,numCols,blockSize);
51 int i = numRows-1;
52 int j = numCols-1;
53 assert(myData.index(i,j) == (i*numCols+j)*blockSize);
54 assert(myData.size() == numRows*numCols*blockSize);
55 }
56
57 {
58 cout << "\t\tnumRows = 3, numCols = 5, blockSize = 20." << endl;
59 int numRows=3;
60 int numCols=5;
61 int blockSize=20;
62 DataBlocks2D myData(numRows,numCols,blockSize);
63 int i = numRows-1;
64 int j = numCols-1;
65 assert(myData.index(i,j) == (i*numCols+j)*blockSize);
66 assert(myData.size() == numRows*numCols*blockSize);
67 }
68
69 {
70 cout << "\t\tnumRows = 3, numCols = 5, blockSize = 1." << endl;
71 int numRows=3;
72 int numCols=5;
73 int blockSize=1;
74 DataBlocks2D myData(numRows,numCols,blockSize);
75 int i = numRows-1;
76 int j = numCols-1;
77 assert(myData.index(i,j) == (i*numCols+j)*blockSize);
78 assert(myData.size() == numRows*numCols*blockSize);
79 }
80
81 {
82 cout << "\t\tnumRows = 1, numCols = 1, blockSize = 1." << endl;
83 int numRows=1;
84 int numCols=1;
85 int blockSize=1;
86 DataBlocks2D myData(numRows,numCols,blockSize);
87 int i = numRows-1;
88 int j = numCols-1;
89 assert(myData.index(i,j) == (i*numCols+j)*blockSize);
90 assert(myData.size() == numRows*numCols*blockSize);
91 }
92
93 {
94 cout << "\tTest DataBlocks2D.index and DataBlocks2D operator[] for blockSize = 3." << endl;
95 int numRows=10;
96 int numCols=8;
97 int blockSize=3;
98 DataBlocks2D myData(numRows,numCols,blockSize);
99 int val=0;
100 for (int i=0; i<numRows; i++) {
101 for (int j=0; j<numCols; j++) {
102 for (int k=0; k<blockSize; k++) {
103 myData[myData.index(i,j)+k] = val;
104 val++;
105 }
106 }
107 }
108 val=0;
109 for (int i=0; i<numRows; i++) {
110 for (int j=0; j<numCols; j++) {
111 for (int k=0; k<blockSize; k++) {
112 assert(myData[myData.index(i,j)+k] == val);
113 val++;
114 }
115 }
116 }
117 }
118
119 {
120 cout << "\tTest DataBlocks2D exception for numRows = 0." << endl;
121 int numRows=0;
122 int numCols=8;
123 int blockSize=10;
124 try {
125 DataBlocks2D myData(numRows,numCols,blockSize);
126 assert(false);
127 }
128 catch(EsysException&) {
129 assert(true);
130 }
131 }
132
133 {
134 cout << "\tTest DataBlocks2D exception for numCols = 0." << endl;
135 int numRows=10;
136 int numCols=0;
137 int blockSize=10;
138 try {
139 DataBlocks2D myData(numRows,numCols,blockSize);
140 assert(false);
141 }
142 catch(EsysException&) {
143 assert(true);
144 }
145 }
146
147 {
148 cout << "\tTest DataBlocks2D exception for blockSize = 0." << endl;
149 int numRows=10;
150 int numCols=8;
151 int blockSize=0;
152 try {
153 DataBlocks2D myData(numRows,numCols,blockSize);
154 assert(false);
155 }
156 catch(EsysException&) {
157 assert(true);
158 }
159 }
160
161 {
162 cout << "\tTest getNumRows, getNumCols and getBlockSize." << endl;
163 int numRows=1;
164 int numCols=1;
165 int blockSize=1;
166 DataBlocks2D myData(numRows,numCols,blockSize);
167 assert(myData.getNumRows() == numRows);
168 assert(myData.getNumCols() == numCols);
169 assert(myData.getBlockSize() == blockSize);
170 }
171
172 {
173 cout << "\tTest resize." << endl;
174 int numRows=1;
175 int numCols=1;
176 int blockSize=1;
177 DataBlocks2D myData;
178 myData.resize(numRows,numCols,blockSize);
179 assert(myData.getNumRows() == numRows);
180 assert(myData.getNumCols() == numCols);
181 assert(myData.getBlockSize() == blockSize);
182 }
183
184 {
185 cout << "\tTest = operator, swap, and copy constructor." << endl;
186 DataBlocks2D myData1;
187 DataBlocks2D myData2(1, 1, 1);
188 int val=0;
189 for (int i=0; i<1; i++) {
190 for (int j=0; j<1; j++) {
191 for (int k=0; k<1; k++) {
192 myData2[myData2.index(i,j)+k] = val;
193 val++;
194 }
195 }
196 }
197 myData1 = myData2;
198 for (int i=0; i<myData1.getNumRows(); i++) {
199 for (int j=0; j<myData1.getNumCols(); j++) {
200 assert(myData1(i,j) == myData2(i,j));
201 }
202 }
203 }
204
205 #if defined DOASSERT
206 {
207 cout << "\tTest DOASSERT exception." << endl;
208 DataBlocks2D myData;
209 try {
210 myData.index(1,2);
211 assert(false);
212 }
213 catch (EsysException&) {
214 assert(true);
215 }
216 }
217 #endif
218
219 }
220
221 TestSuite* DataBlocks2DTestCase::suite ()
222 {
223 //
224 // create the suite of tests to perform.
225 TestSuite *testSuite = new TestSuite ("DataBlocks2DTestCase");
226
227 testSuite->addTest (new TestCaller< DataBlocks2DTestCase>("testAll",&DataBlocks2DTestCase::testAll));
228 return testSuite;
229 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26