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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3597 - (show annotations)
Thu Sep 15 06:03:17 2011 UTC (8 years, 2 months ago) by caltinay
File size: 5504 byte(s)
Switching to external cppunit:
-removed tools/CppUnitTest
-updated scons script and files
-updated tests to changed API
-updated readme

Bumped scons options file version to 201. Additions:
-cppunit*
-boomeramg*
-vsl_random


1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 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 "DataBlocks2DTestCase.h"
16 #include "escript/DataBlocks2D.h"
17 #include "esysUtils/EsysException.h"
18
19 #include <cppunit/TestCaller.h>
20 #include <iostream>
21
22 using namespace std;
23 using namespace CppUnit;
24 using namespace escript;
25 using namespace esysUtils;
26
27 void DataBlocks2DTestCase::testAll()
28 {
29 cout << endl;
30 cout << "\tTest DataBlocks2D constructor for various dimension values:" << endl;
31
32 {
33 cout << "\t\tnumRows = 1, numCols = 1, blockSize = 20." << endl;
34 int numRows=1;
35 int numCols=1;
36 int blockSize=20;
37 DataBlocks2D myData(numRows,numCols,blockSize);
38 int i = numRows-1;
39 int j = numCols-1;
40 CPPUNIT_ASSERT(myData.index(i,j) == (i*numCols+j)*blockSize);
41 CPPUNIT_ASSERT(myData.size() == numRows*numCols*blockSize);
42 }
43
44 {
45 cout << "\t\tnumRows = 3, numCols = 5, blockSize = 20." << endl;
46 int numRows=3;
47 int numCols=5;
48 int blockSize=20;
49 DataBlocks2D myData(numRows,numCols,blockSize);
50 int i = numRows-1;
51 int j = numCols-1;
52 CPPUNIT_ASSERT(myData.index(i,j) == (i*numCols+j)*blockSize);
53 CPPUNIT_ASSERT(myData.size() == numRows*numCols*blockSize);
54 }
55
56 {
57 cout << "\t\tnumRows = 3, numCols = 5, blockSize = 1." << endl;
58 int numRows=3;
59 int numCols=5;
60 int blockSize=1;
61 DataBlocks2D myData(numRows,numCols,blockSize);
62 int i = numRows-1;
63 int j = numCols-1;
64 CPPUNIT_ASSERT(myData.index(i,j) == (i*numCols+j)*blockSize);
65 CPPUNIT_ASSERT(myData.size() == numRows*numCols*blockSize);
66 }
67
68 {
69 cout << "\t\tnumRows = 1, numCols = 1, blockSize = 1." << endl;
70 int numRows=1;
71 int numCols=1;
72 int blockSize=1;
73 DataBlocks2D myData(numRows,numCols,blockSize);
74 int i = numRows-1;
75 int j = numCols-1;
76 CPPUNIT_ASSERT(myData.index(i,j) == (i*numCols+j)*blockSize);
77 CPPUNIT_ASSERT(myData.size() == numRows*numCols*blockSize);
78 }
79
80 {
81 cout << "\tTest DataBlocks2D.index and DataBlocks2D operator[] for blockSize = 3." << endl;
82 int numRows=10;
83 int numCols=8;
84 int blockSize=3;
85 DataBlocks2D myData(numRows,numCols,blockSize);
86 int val=0;
87 for (int i=0; i<numRows; i++) {
88 for (int j=0; j<numCols; j++) {
89 for (int k=0; k<blockSize; k++) {
90 myData[myData.index(i,j)+k] = val;
91 val++;
92 }
93 }
94 }
95 val=0;
96 for (int i=0; i<numRows; i++) {
97 for (int j=0; j<numCols; j++) {
98 for (int k=0; k<blockSize; k++) {
99 CPPUNIT_ASSERT(myData[myData.index(i,j)+k] == val);
100 val++;
101 }
102 }
103 }
104 }
105
106 {
107 cout << "\tTest DataBlocks2D exception for numRows = 0." << endl;
108 int numRows=0;
109 int numCols=8;
110 int blockSize=10;
111 try {
112 DataBlocks2D myData(numRows,numCols,blockSize);
113 CPPUNIT_FAIL("Exception not thrown");
114 }
115 catch(EsysException&) {
116 CPPUNIT_ASSERT(true);
117 }
118 }
119
120 {
121 cout << "\tTest DataBlocks2D exception for numCols = 0." << endl;
122 int numRows=10;
123 int numCols=0;
124 int blockSize=10;
125 try {
126 DataBlocks2D myData(numRows,numCols,blockSize);
127 CPPUNIT_FAIL("Exception not thrown");
128 }
129 catch(EsysException&) {
130 CPPUNIT_ASSERT(true);
131 }
132 }
133
134 {
135 cout << "\tTest DataBlocks2D exception for blockSize = 0." << endl;
136 int numRows=10;
137 int numCols=8;
138 int blockSize=0;
139 try {
140 DataBlocks2D myData(numRows,numCols,blockSize);
141 CPPUNIT_FAIL("Exception not thrown");
142 }
143 catch(EsysException&) {
144 CPPUNIT_ASSERT(true);
145 }
146 }
147
148 {
149 cout << "\tTest getNumRows, getNumCols and getBlockSize." << endl;
150 int numRows=1;
151 int numCols=1;
152 int blockSize=1;
153 DataBlocks2D myData(numRows,numCols,blockSize);
154 CPPUNIT_ASSERT(myData.getNumRows() == numRows);
155 CPPUNIT_ASSERT(myData.getNumCols() == numCols);
156 CPPUNIT_ASSERT(myData.getBlockSize() == blockSize);
157 }
158
159 {
160 cout << "\tTest resize." << endl;
161 int numRows=1;
162 int numCols=1;
163 int blockSize=1;
164 DataBlocks2D myData;
165 myData.resize(numRows,numCols,blockSize);
166 CPPUNIT_ASSERT(myData.getNumRows() == numRows);
167 CPPUNIT_ASSERT(myData.getNumCols() == numCols);
168 CPPUNIT_ASSERT(myData.getBlockSize() == blockSize);
169 }
170
171 {
172 cout << "\tTest = operator, swap, and copy constructor." << endl;
173 DataBlocks2D myData1;
174 DataBlocks2D myData2(1, 1, 1);
175 int val=0;
176 for (int i=0; i<1; i++) {
177 for (int j=0; j<1; j++) {
178 for (int k=0; k<1; k++) {
179 myData2[myData2.index(i,j)+k] = val;
180 val++;
181 }
182 }
183 }
184 myData1 = myData2;
185 for (int i=0; i<myData1.getNumRows(); i++) {
186 for (int j=0; j<myData1.getNumCols(); j++) {
187 CPPUNIT_ASSERT(myData1(i,j) == myData2(i,j));
188 }
189 }
190 }
191
192 #if defined DOASSERT
193 {
194 cout << "\tTest DOASSERT exception." << endl;
195 DataBlocks2D myData;
196 CPPUNIT_ASSERT_THROW(myData.index(1,2), EsysException);
197 }
198 #endif
199 }
200
201 TestSuite* DataBlocks2DTestCase::suite()
202 {
203 TestSuite *testSuite = new TestSuite("DataBlocks2DTestCase");
204
205 testSuite->addTest(new TestCaller<DataBlocks2DTestCase>(
206 "testAll",&DataBlocks2DTestCase::testAll));
207 return testSuite;
208 }
209

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26