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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (show annotations)
Fri May 6 04:26:16 2005 UTC (14 years, 9 months ago) by jgs
Original Path: trunk/esys2/escript/test/Taipan/TaipanTestCase.cpp
File size: 12293 byte(s)
Merge of development branch back to main trunk on 2005-05-06

1 /*
2 *****************************************************************************
3 * *
4 * COPYRIGHT ACcESS - All Rights Reserved *
5 * *
6 * This software is the property of ACcESS. No part of this code *
7 * may be copied in any form or by any means without the expressed written *
8 * consent of ACcESS. Copying, use or modification of this software *
9 * by any unauthorised person is illegal unless that person has a software *
10 * license agreement with ACcESS. *
11 * *
12 *****************************************************************************
13 */
14
15 #include "escript/Data/Taipan.h"
16 #include "esysUtils/EsysException.h"
17
18 #include "TaipanTestCase.h"
19
20 #include <iostream>
21
22 using namespace std;
23 using namespace escript;
24 using namespace esysUtils;
25 using namespace CppUnitTest;
26
27 void TaipanTestCase::setUp() {
28 //
29 // This is called before each test is run
30
31 }
32
33 void TaipanTestCase::tearDown() {
34 //
35 // This is called after each test has been run
36
37 }
38
39 void TaipanTestCase::testAll() {
40 //
41 // The test code may be entered here
42 // There is nothing special about the function name, it may be renamed to
43 // something more suitable.
44 // As many test methods as desired may be added.
45
46 cout << endl;
47
48 const int dim = 1;
49
50 Taipan t;
51
52 cout << "\tTest empty Taipan memTable." << endl;
53
54 assert(t.num_arrays() == 0);
55 assert(t.num_elements() == 0);
56
57 cout << "\tTest Taipan memTable with one array of size 0 under management." << endl;
58
59 double* array = t.new_array(dim,0);
60
61 assert(t.num_arrays() == 1);
62 assert(t.num_arrays(0) == 1);
63 assert(t.num_free(0) == 0);
64 assert(t.num_elements() == 0);
65
66 t.delete_array(array);
67
68 assert(t.num_arrays() == 0);
69 assert(t.num_elements() == 0);
70
71 cout << "\tTest Taipan memTable with one array of size 1 under management." << endl;
72
73 array = t.new_array(dim,1);
74
75 //array[0] = 0;
76
77 assert(array[0] == 0.0);
78
79 assert(t.num_arrays() == 1);
80 assert(t.num_arrays(1) == 1);
81 assert(t.num_free(1) == 0);
82 assert(t.num_elements() == 1);
83
84 t.delete_array(array);
85
86 assert(t.num_arrays() == 0);
87 assert(t.num_elements() == 0);
88
89 cout << "\tTest Taipan memTable with one array of size 10 under management." << endl;
90
91 array = t.new_array(dim,10);
92
93 for (int i=0; i<10; i++) {
94 assert(array[i] == 0.0);
95 }
96
97 for (int i=0; i<10; i++) {
98 array[i] = i;
99 }
100 for (int i=0; i<10; i++) {
101 assert(array[i] == i);
102 }
103
104 assert(t.num_arrays() == 1);
105 assert(t.num_arrays(10) == 1);
106 assert(t.num_free(10) == 0);
107 assert(t.num_elements() == 10);
108
109 t.delete_array(array);
110
111 assert(t.num_arrays() == 0);
112 assert(t.num_elements() == 0);
113
114 cout << "\tTest Taipan memTable with ten arrays of size 0 under management." << endl;
115
116 // allocate all ten arrays
117 // the number of arrays under management will increase with each allocation
118 double* arraY[10];
119 for (int i=0; i<10; i++) {
120 arraY[i] = t.new_array(dim,0);
121 assert(t.num_arrays() == i+1);
122 assert(t.num_arrays(0) == i+1);
123 assert(t.num_free(0) == 0);
124 assert(t.num_elements() == 0);
125 }
126
127 // delete all but the last array under management
128 // the number of arrays under management does not change
129 // but the number of free arrays will increase with each deallocation
130 for (int i=0; i<9; i++) {
131 t.delete_array(arraY[i]);
132 assert(t.num_arrays() == 10);
133 assert(t.num_arrays(0) == 10);
134 assert(t.num_free(0) == i+1);
135 assert(t.num_elements() == 0);
136 }
137
138 // now reallocate the 9 free arrays
139 // the preserved arrays will be reused
140 // and the number of free arrays will decrease with each allocation
141 for (int i=0; i<9; i++) {
142 arraY[i] = t.new_array(dim,0);
143 assert(t.num_arrays() == 10);
144 assert(t.num_arrays(0) == 10);
145 assert(t.num_free(0) == 8-i);
146 assert(t.num_elements() == 0);
147 }
148
149 // delete all but the last array under management
150 // the number of arrays under management does not change
151 // but the number of free arrays will increase with each deallocation
152 for (int i=0; i<9; i++) {
153 t.delete_array(arraY[i]);
154 assert(t.num_arrays() == 10);
155 assert(t.num_arrays(0) == 10);
156 assert(t.num_free(0) == i+1);
157 assert(t.num_elements() == 0);
158 }
159
160 // finally delete the last array
161 // all arrays under management are deleted
162 t.delete_array(arraY[9]);
163 assert(t.num_arrays() == 0);
164 assert(t.num_elements() == 0);
165
166 cout << "\tTest Taipan memTable with ten arrays of size 1 under management." << endl;
167
168 // allocate all ten arrays
169 // the number of arrays under management will increase with each allocation
170 arraY[10];
171 for (int i=0; i<10; i++) {
172 arraY[i] = t.new_array(dim,1);
173 assert(t.num_arrays() == i+1);
174 assert(t.num_arrays(1) == i+1);
175 assert(t.num_free(1) == 0);
176 assert(t.num_elements() == i+1);
177 }
178
179 for (int i=0; i<10; i++) {
180 arraY[i][0] = i;
181 }
182 for (int i=0; i<10; i++) {
183 assert(arraY[i][0] == i);
184 }
185
186 // delete all but the last array under management
187 // the number of arrays under management does not change
188 // but the number of free arrays will increase with each deallocation
189 for (int i=0; i<9; i++) {
190 t.delete_array(arraY[i]);
191 assert(t.num_arrays() == 10);
192 assert(t.num_arrays(1) == 10);
193 assert(t.num_free(1) == i+1);
194 assert(t.num_elements() == 10);
195 }
196 assert(arraY[9][0] == 9);
197
198 // now reallocate the 9 free arrays
199 // the preserved arrays will be reused
200 // and the number of free arrays will decrease with each allocation
201 for (int i=0; i<9; i++) {
202 arraY[i] = t.new_array(dim,1);
203 assert(t.num_arrays() == 10);
204 assert(t.num_arrays(1) == 10);
205 assert(t.num_free(1) == 8-i);
206 assert(t.num_elements() == 10);
207 }
208 for (int i=0; i<10; i++) {
209 assert(arraY[i][0] == i);
210 }
211
212 // delete all but the last array under management
213 // the number of arrays under management does not change
214 // but the number of free arrays will increase with each deallocation
215 for (int i=0; i<9; i++) {
216 t.delete_array(arraY[i]);
217 assert(t.num_arrays() == 10);
218 assert(t.num_arrays(1) == 10);
219 assert(t.num_free(1) == i+1);
220 assert(t.num_elements() == 10);
221 }
222 assert(arraY[9][0] == 9);
223
224 // finally delete the last array
225 // all arrays under management are deleted
226 t.delete_array(arraY[9]);
227 assert(t.num_arrays() == 0);
228 assert(t.num_elements() == 0);
229
230 cout << "\tTest Taipan memTable with ten arrays of size 10 under management." << endl;
231
232 // allocate all ten arrays
233 // the number of arrays under management will increase with each allocation
234 arraY[10];
235 for (int i=0; i<10; i++) {
236 arraY[i] = t.new_array(dim,10);
237 assert(t.num_arrays() == i+1);
238 assert(t.num_arrays(10) == i+1);
239 assert(t.num_free(10) == 0);
240 assert(t.num_elements() == (i+1)*10);
241 }
242
243 int val = 0;
244 for (int i=0; i<10; i++) {
245 for (int j=0; j<10; j++) {
246 arraY[i][j] = val;
247 val++;
248 }
249 }
250 val = 0;
251 for (int i=0; i<10; i++) {
252 for (int j=0; j<10; j++) {
253 assert(arraY[i][j] == val);
254 val++;
255 }
256 }
257
258 // delete all but the last array under management
259 // the number of arrays under management does not change
260 // but the number of free arrays will increase with each deallocation
261 for (int i=0; i<9; i++) {
262 t.delete_array(arraY[i]);
263 assert(t.num_arrays() == 10);
264 assert(t.num_arrays(10) == 10);
265 assert(t.num_free(10) == i+1);
266 assert(t.num_elements() == 100);
267 }
268 val = 90;
269 for (int j=0; j<10; j++) {
270 assert(arraY[9][j] == val);
271 val++;
272 }
273
274 // now reallocate the 9 free arrays
275 // the preserved arrays will be reused
276 // and the number of free arrays will decrease with each allocation
277 for (int i=0; i<9; i++) {
278 arraY[i] = t.new_array(dim,10);
279 assert(t.num_arrays() == 10);
280 assert(t.num_arrays(10) == 10);
281 assert(t.num_free(10) == 8-i);
282 assert(t.num_elements() == 100);
283 }
284 val = 0;
285 for (int i=0; i<10; i++) {
286 for (int j=0; j<10; j++) {
287 assert(arraY[i][j] == val);
288 val++;
289 }
290 }
291
292 // delete all but the last array under management
293 // the number of arrays under management does not change
294 // but the number of free arrays will increase with each deallocation
295 for (int i=0; i<9; i++) {
296 t.delete_array(arraY[i]);
297 assert(t.num_arrays() == 10);
298 assert(t.num_arrays(10) == 10);
299 assert(t.num_free(10) == i+1);
300 assert(t.num_elements() == 100);
301 }
302 val = 90;
303 for (int j=0; j<10; j++) {
304 assert(arraY[9][j] == val);
305 val++;
306 }
307
308 // finally delete the last array
309 // all arrays under management are deleted
310 t.delete_array(arraY[9]);
311 assert(t.num_arrays() == 0);
312 assert(t.num_elements() == 0);
313
314 cout << "\tTest Taipan memTable with ten arrays of various sizes under management." << endl;
315
316 // allocate all ten arrays
317 // the number of arrays under management will increase with each allocation
318 arraY[0] = t.new_array(dim,0);
319 arraY[1] = t.new_array(dim,1);
320 arraY[2] = t.new_array(dim,1);
321 arraY[3] = t.new_array(dim,10);
322 arraY[4] = t.new_array(dim,10);
323 arraY[5] = t.new_array(dim,10);
324 arraY[6] = t.new_array(dim,100);
325 arraY[7] = t.new_array(dim,100);
326 arraY[8] = t.new_array(dim,100);
327 arraY[9] = t.new_array(dim,100);
328
329 assert(t.num_arrays() == 10);
330 assert(t.num_arrays(0) == 1);
331 assert(t.num_arrays(1) == 2);
332 assert(t.num_arrays(10) == 3);
333 assert(t.num_arrays(100) == 4);
334 assert(t.num_free(0) == 0);
335 assert(t.num_free(1) == 0);
336 assert(t.num_free(10) == 0);
337 assert(t.num_free(100) == 0);
338 assert(t.num_elements() == 432);
339
340 // delete all but the last array of each size under management
341 // the number of arrays under management does not change
342 // but the number of free arrays will increase with each deallocation
343 t.delete_array(arraY[2]);
344 t.delete_array(arraY[4]);
345 t.delete_array(arraY[5]);
346 t.delete_array(arraY[7]);
347 t.delete_array(arraY[8]);
348 t.delete_array(arraY[9]);
349
350 assert(t.num_arrays() == 10);
351 assert(t.num_arrays(0) == 1);
352 assert(t.num_arrays(1) == 2);
353 assert(t.num_arrays(10) == 3);
354 assert(t.num_arrays(100) == 4);
355 assert(t.num_free(0) == 0);
356 assert(t.num_free(1) == 1);
357 assert(t.num_free(10) == 2);
358 assert(t.num_free(100) == 3);
359 assert(t.num_elements() == 432);
360
361 // now reallocate the free arrays
362 // the preserved arrays will be reused
363 // and the number of free arrays will decrease with each allocation
364 arraY[2] = t.new_array(dim,1);
365 arraY[4] = t.new_array(dim,10);
366 arraY[5] = t.new_array(dim,10);
367 arraY[7] = t.new_array(dim,100);
368 arraY[8] = t.new_array(dim,100);
369 arraY[9] = t.new_array(dim,100);
370
371 assert(t.num_arrays() == 10);
372 assert(t.num_arrays(0) == 1);
373 assert(t.num_arrays(1) == 2);
374 assert(t.num_arrays(10) == 3);
375 assert(t.num_arrays(100) == 4);
376 assert(t.num_free(0) == 0);
377 assert(t.num_free(1) == 0);
378 assert(t.num_free(10) == 0);
379 assert(t.num_free(100) == 0);
380 assert(t.num_elements() == 432);
381
382 // delete all but the last array of each size under management
383 // the number of arrays under management does not change
384 // but the number of free arrays will increase with each deallocation
385 t.delete_array(arraY[2]);
386 t.delete_array(arraY[4]);
387 t.delete_array(arraY[5]);
388 t.delete_array(arraY[7]);
389 t.delete_array(arraY[8]);
390 t.delete_array(arraY[9]);
391
392 assert(t.num_arrays() == 10);
393 assert(t.num_arrays(0) == 1);
394 assert(t.num_arrays(1) == 2);
395 assert(t.num_arrays(10) == 3);
396 assert(t.num_arrays(100) == 4);
397 assert(t.num_free(0) == 0);
398 assert(t.num_free(1) == 1);
399 assert(t.num_free(10) == 2);
400 assert(t.num_free(100) == 3);
401 assert(t.num_elements() == 432);
402
403 // deallocate the last of the arrays
404 t.delete_array(arraY[0]);
405 t.delete_array(arraY[1]);
406 t.delete_array(arraY[3]);
407 t.delete_array(arraY[6]);
408
409 assert(t.num_arrays() == 0);
410 assert(t.num_elements() == 0);
411 }
412
413 TestSuite* TaipanTestCase::suite ()
414 {
415 //
416 // create the suite of tests to perform.
417 TestSuite *testSuite = new TestSuite ("TaipanTestCase");
418
419 testSuite->addTest (new TestCaller< TaipanTestCase>("testAll",&TaipanTestCase::testAll));
420 return testSuite;
421 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26