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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (hide annotations)
Tue Oct 26 06:53:54 2004 UTC (14 years, 11 months ago) by jgs
Original Path: trunk/esys2/escript/test/DataBlocks2D/DataBlocks2DTestCase.cpp
File size: 5128 byte(s)
Initial revision

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     #include "escript/Data/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     {
44     cout << "\tTest DOASSERT exception." << endl;
45     DataBlocks2D myData;
46     try {
47     myData.index(1,2);
48     assert(false);
49     }
50     catch (EsysException& e) {
51     //std::cout << e.what() << std::endl;
52     assert(true);
53     }
54     }
55    
56     cout << "\tTest DataBlocks2D constructor for various size arrays:" << endl;
57    
58     {
59     cout << "\t\tnumRows = 1, numCols = 1, blockSize = 20." << endl;
60     int numRows=1;
61     int numCols=1;
62     int blockSize=20;
63     DataBlocks2D myData(numRows,numCols,blockSize);
64     assert(myData.index(numRows-1,numCols-1) == ((numRows-1)*(numCols-1)*blockSize));
65     assert(myData.getData().size() == numRows*numCols*blockSize);
66     }
67    
68     {
69     cout << "\t\tnumRows = 3, numCols = 5, blockSize = 20." << endl;
70     int numRows=3;
71     int numCols=5;
72     int blockSize=20;
73     DataBlocks2D myData(numRows,numCols,blockSize);
74     assert(myData.index(numRows-1,numCols-1) == ((numRows*numCols-1)*blockSize));
75     assert(myData.getData().size() == numRows*numCols*blockSize);
76     }
77    
78     {
79     cout << "\t\tnumRows = 3, numCols = 5, blockSize = 1." << endl;
80     int numRows=3;
81     int numCols=5;
82     int blockSize=1;
83     DataBlocks2D myData(numRows,numCols,blockSize);
84     assert(myData.index(numRows-1,numCols-1) == ((numRows*numCols-1)*blockSize));
85     assert(myData.getData().size() == numRows*numCols*blockSize);
86     }
87    
88     {
89     cout << "\t\tnumRows = 1, numCols = 1, blockSize = 1." << endl;
90     int numRows=1;
91     int numCols=1;
92     int blockSize=1;
93     DataBlocks2D myData(numRows,numCols,blockSize);
94     assert(myData.index(numRows-1,numCols-1) == ((numRows*numCols-1)*blockSize));
95     assert(myData.getData().size() == numRows*numCols*blockSize);
96     }
97    
98     {
99     cout << "\tTest DataBlocks2D.index and DataBlocks2D.getData for blockSize = 3." << endl;
100     int numRows=10;
101     int numCols=8;
102     int blockSize=3;
103     DataBlocks2D myData(numRows,numCols,blockSize);
104     for (int iR=0;iR<numRows;++iR) {
105     for (int iC=0;iC<numCols;++iC) {
106     //cout << "i=" << iR << " j=" << iC << " index=" << myData.index(iR,iC) << endl;
107     assert(myData.getData()[myData.index(iR,iC)] == 0);
108     }
109     }
110     }
111    
112     {
113     cout << "\tTest DataBlocks2D.getData for blockSize = 0 - will generate exceptions." << endl;
114     //
115     // every attempted access for a 0 size block should cause an exception
116     int numRows=10;
117     int numCols=8;
118     int blockSize=0;
119     int exceptionCount=0;
120     DataBlocks2D myData(numRows,numCols,blockSize);
121     for (int iR=0;iR<numRows;++iR) {
122     for (int iC=0;iC<numCols;++iC) {
123     try {
124     myData.getData()[myData.index(iR,iC)];
125     assert(false);
126     }
127     catch(EsysException& e) {
128     //cout << e.toString() << endl;
129     ++exceptionCount;
130     assert(true);
131     }
132     }
133     }
134     assert(exceptionCount == numRows*numCols);
135     }
136    
137     {
138     cout << "\tTest getNumRows and getNumCols." << endl;
139     int numRows=1;
140     int numCols=1;
141     int blockSize=1;
142     DataBlocks2D myData(numRows,numCols,blockSize);
143     assert(myData.getNumRows() == numRows);
144     assert(myData.getNumCols() == numCols);
145     }
146    
147     {
148     cout << "\tTest resize." << endl;
149     int numRows=1;
150     int numCols=1;
151     int blockSize=1;
152     DataBlocks2D myData;
153     myData.resize(numRows,numCols,blockSize);
154     assert(myData.getNumRows() == numRows);
155     assert(myData.getNumCols() == numCols);
156     }
157    
158     {
159     cout << "\tTest = operator, swap, and copy constructor." << endl;
160     DataBlocks2D myData1;
161     DataBlocks2D myData2(1, 1, 1);
162     myData1 = myData2;
163     }
164    
165     }
166    
167     TestSuite* DataBlocks2DTestCase::suite ()
168     {
169     //
170     // create the suite of tests to perform.
171     TestSuite *testSuite = new TestSuite ("DataBlocks2DTestCase");
172    
173     testSuite->addTest (new TestCaller< DataBlocks2DTestCase>("testAll",&DataBlocks2DTestCase::testAll));
174     return testSuite;
175     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26