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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/escript/test/Taipan/TaipanTestCase.cpp revision 121 by jgs, Fri May 6 04:26:16 2005 UTC trunk/escript/test/TaipanTestCase.cpp revision 1388 by trankine, Fri Jan 11 07:45:58 2008 UTC
# Line 1  Line 1 
 /*  
  *****************************************************************************  
  *                                                                           *  
  *       COPYRIGHT  ACcESS  -  All Rights Reserved                           *  
  *                                                                           *  
  * This software is the property of ACcESS. No part of this code             *  
  * may be copied in any form or by any means without the expressed written   *  
  * consent of ACcESS.  Copying, use or modification of this software         *  
  * by any unauthorised person is illegal unless that person has a software   *  
  * license agreement with ACcESS.                                            *  
  *                                                                           *  
  *****************************************************************************  
 */  
1    
2  #include "escript/Data/Taipan.h"  /* $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    #include "escript/Taipan.h"
17  #include "esysUtils/EsysException.h"  #include "esysUtils/EsysException.h"
18    
19  #include "TaipanTestCase.h"  #include "TaipanTestCase.h"
# Line 36  void TaipanTestCase::tearDown() { Line 37  void TaipanTestCase::tearDown() {
37    
38  }  }
39    
40  void TaipanTestCase::testAll() {  void TaipanTestCase::testN1() {
   //  
   // The test code may be entered here  
   // There is nothing special about the function name, it may be renamed to  
   // something more suitable.  
   // As many test methods as desired may be added.  
41    
42    cout << endl;    // Arrays with N=1 are handled differently by the Taipan memory manager, these
43      // are never disposed of to maximise reusability, so they are tested seperately.
44    
45    const int dim = 1;    cout << endl;
46    
47    Taipan t;    Taipan t;
48    
49    cout << "\tTest empty Taipan memTable." << endl;    const int dim = 1;
   
   assert(t.num_arrays() == 0);  
   assert(t.num_elements() == 0);  
   
   cout << "\tTest Taipan memTable with one array of size 0 under management." << endl;  
   
   double* array = t.new_array(dim,0);  
   
   assert(t.num_arrays() == 1);  
   assert(t.num_arrays(0) == 1);  
   assert(t.num_free(0) == 0);  
   assert(t.num_elements() == 0);  
   
   t.delete_array(array);  
50    
51    assert(t.num_arrays() == 0);    double* array;
52    assert(t.num_elements() == 0);    double* arraY[10];
53    
54    cout << "\tTest Taipan memTable with one array of size 1 under management." << endl;    cout << "\tTest Taipan memTable with one array of size 1 under management." << endl;
55    
56    array = t.new_array(dim,1);    array = t.new_array(dim,1);
57    
   //array[0] = 0;  
   
58    assert(array[0] == 0.0);    assert(array[0] == 0.0);
59    
60    assert(t.num_arrays() == 1);    assert(t.num_arrays() == 1);
# Line 83  void TaipanTestCase::testAll() { Line 64  void TaipanTestCase::testAll() {
64    
65    t.delete_array(array);    t.delete_array(array);
66    
67    assert(t.num_arrays() == 0);    assert(t.num_arrays() == 1);
68    assert(t.num_elements() == 0);    assert(t.num_elements() == 1);
   
   cout << "\tTest Taipan memTable with one array of size 10 under management." << endl;  
69    
70    array = t.new_array(dim,10);    cout << "\tTest Taipan memTable with ten arrays of size 1 under management." << endl;
71    
72      // allocate all ten arrays
73      // the number of arrays under management will increase with each allocation
74      arraY[10];
75    for (int i=0; i<10; i++) {    for (int i=0; i<10; i++) {
76      assert(array[i] == 0.0);      arraY[i] = t.new_array(dim,1);
77        assert(t.num_arrays() == i+1);
78        assert(t.num_arrays(1) == i+1);
79        assert(t.num_free(1) == 0);
80        assert(t.num_elements() == i+1);
81    }    }
82    
83    for (int i=0; i<10; i++) {    for (int i=0; i<10; i++) {
84      array[i] = i;      arraY[i][0] = i;
85    }    }
86    for (int i=0; i<10; i++) {    for (int i=0; i<10; i++) {
87      assert(array[i] == i);      assert(arraY[i][0] == i);
88    }    }
89    
90    assert(t.num_arrays() == 1);    // delete all but the last array under management
91    assert(t.num_arrays(10) == 1);    // the number of arrays under management does not change
92    assert(t.num_free(10) == 0);    // but the number of free arrays will increase with each deallocation
93      for (int i=0; i<9; i++) {
94        t.delete_array(arraY[i]);
95        assert(t.num_arrays() == 10);
96        assert(t.num_arrays(1) == 10);
97        assert(t.num_free(1) == i+1);
98        assert(t.num_elements() == 10);
99      }
100      assert(arraY[9][0] == 9);
101    
102      // now reallocate the 9 free arrays
103      // the preserved arrays will be reused
104      // and the number of free arrays will decrease with each allocation
105      for (int i=0; i<9; i++) {
106        arraY[i] = t.new_array(dim,1);
107        assert(t.num_arrays() == 10);
108        assert(t.num_arrays(1) == 10);
109        assert(t.num_free(1) == 8-i);
110        assert(t.num_elements() == 10);
111      }
112      for (int i=0; i<10; i++) {
113        assert(arraY[i][0] == i);
114      }
115    
116      // delete all but the last array under management
117      // the number of arrays under management does not change
118      // but the number of free arrays will increase with each deallocation
119      for (int i=0; i<9; i++) {
120        t.delete_array(arraY[i]);
121        assert(t.num_arrays() == 10);
122        assert(t.num_arrays(1) == 10);
123        assert(t.num_free(1) == i+1);
124        assert(t.num_elements() == 10);
125      }
126      assert(arraY[9][0] == 9);
127    
128      // finally delete the last array
129      t.delete_array(arraY[9]);
130      assert(t.num_arrays() == 10);
131    assert(t.num_elements() == 10);    assert(t.num_elements() == 10);
132    }
133    
134    void TaipanTestCase::testN0() {
135    
136      // Arrays with N=0 are handled differently by the Taipan memory manager, these
137      // are never disposed of to maximise reusability, so they are tested seperately.
138    
139      cout << endl;
140    
141      Taipan t;
142    
143      const int dim = 1;
144    
145      double* array;
146      double* arraY[10];
147    
148      cout << "\tTest Taipan memTable with one array of size 0 under management." << endl;
149    
150      array = t.new_array(dim,0);
151    
152      assert(t.num_arrays() == 1);
153      assert(t.num_arrays(0) == 1);
154      assert(t.num_free(0) == 0);
155      assert(t.num_elements() == 0);
156    
157    t.delete_array(array);    t.delete_array(array);
158    
159    assert(t.num_arrays() == 0);    assert(t.num_arrays() == 1);
160    assert(t.num_elements() == 0);    assert(t.num_elements() == 0);
161    
162    cout << "\tTest Taipan memTable with ten arrays of size 0 under management." << endl;    cout << "\tTest Taipan memTable with ten arrays of size 0 under management." << endl;
163    
164    // allocate all ten arrays    // allocate all ten arrays
165    // the number of arrays under management will increase with each allocation    // the number of arrays under management will increase with each allocation
   double* arraY[10];  
166    for (int i=0; i<10; i++) {    for (int i=0; i<10; i++) {
167      arraY[i] = t.new_array(dim,0);      arraY[i] = t.new_array(dim,0);
168      assert(t.num_arrays() == i+1);      assert(t.num_arrays() == i+1);
# Line 158  void TaipanTestCase::testAll() { Line 205  void TaipanTestCase::testAll() {
205    }    }
206    
207    // finally delete the last array    // finally delete the last array
   // all arrays under management are deleted  
208    t.delete_array(arraY[9]);    t.delete_array(arraY[9]);
209      assert(t.num_arrays() == 10);
210      assert(t.num_elements() == 0);
211    }
212    
213    void TaipanTestCase::testAll() {
214    
215      cout << endl;
216    
217      Taipan t;
218    
219      double* array;
220      double* arraY[10];
221    
222      const int dim = 1;
223    
224      cout << "\tTest empty Taipan memTable." << endl;
225    
226    assert(t.num_arrays() == 0);    assert(t.num_arrays() == 0);
227    assert(t.num_elements() == 0);    assert(t.num_elements() == 0);
228    
229    cout << "\tTest Taipan memTable with ten arrays of size 1 under management." << endl;    cout << "\tTest Taipan memTable with one array of size 10 under management." << endl;
230    
231      array = t.new_array(dim,10);
232    
   // allocate all ten arrays  
   // the number of arrays under management will increase with each allocation  
   arraY[10];  
233    for (int i=0; i<10; i++) {    for (int i=0; i<10; i++) {
234      arraY[i] = t.new_array(dim,1);      assert(array[i] == 0.0);
     assert(t.num_arrays() == i+1);  
     assert(t.num_arrays(1) == i+1);  
     assert(t.num_free(1) == 0);  
     assert(t.num_elements() == i+1);  
235    }    }
236    
237    for (int i=0; i<10; i++) {    for (int i=0; i<10; i++) {
238      arraY[i][0] = i;      array[i] = i;
239    }    }
240    for (int i=0; i<10; i++) {    for (int i=0; i<10; i++) {
241      assert(arraY[i][0] == i);      assert(array[i] == i);
   }  
   
   // delete all but the last array under management  
   // the number of arrays under management does not change  
   // but the number of free arrays will increase with each deallocation  
   for (int i=0; i<9; i++) {  
     t.delete_array(arraY[i]);  
     assert(t.num_arrays() == 10);  
     assert(t.num_arrays(1) == 10);  
     assert(t.num_free(1) == i+1);  
     assert(t.num_elements() == 10);  
242    }    }
   assert(arraY[9][0] == 9);  
243    
244    // now reallocate the 9 free arrays    assert(t.num_arrays() == 1);
245    // the preserved arrays will be reused    assert(t.num_arrays(10) == 1);
246    // and the number of free arrays will decrease with each allocation    assert(t.num_free(10) == 0);
247    for (int i=0; i<9; i++) {    assert(t.num_elements() == 10);
     arraY[i] = t.new_array(dim,1);  
     assert(t.num_arrays() == 10);  
     assert(t.num_arrays(1) == 10);  
     assert(t.num_free(1) == 8-i);  
     assert(t.num_elements() == 10);  
   }  
   for (int i=0; i<10; i++) {  
     assert(arraY[i][0] == i);  
   }  
248    
249    // delete all but the last array under management    t.delete_array(array);
   // the number of arrays under management does not change  
   // but the number of free arrays will increase with each deallocation  
   for (int i=0; i<9; i++) {  
     t.delete_array(arraY[i]);  
     assert(t.num_arrays() == 10);  
     assert(t.num_arrays(1) == 10);  
     assert(t.num_free(1) == i+1);  
     assert(t.num_elements() == 10);  
   }  
   assert(arraY[9][0] == 9);  
250    
   // finally delete the last array  
   // all arrays under management are deleted  
   t.delete_array(arraY[9]);  
251    assert(t.num_arrays() == 0);    assert(t.num_arrays() == 0);
252    assert(t.num_elements() == 0);    assert(t.num_elements() == 0);
253    
254    cout << "\tTest Taipan memTable with ten arrays of size 10 under management." << endl;    cout << "\tTest Taipan memTable with ten arrays of size 10 under management." << endl;
255    
256    // allocate all ten arrays    // allocate all ten arrays
# Line 315  void TaipanTestCase::testAll() { Line 339  void TaipanTestCase::testAll() {
339    
340    // allocate all ten arrays    // allocate all ten arrays
341    // the number of arrays under management will increase with each allocation    // the number of arrays under management will increase with each allocation
342    arraY[0] = t.new_array(dim,0);    arraY[0] = t.new_array(dim,2);
343    arraY[1] = t.new_array(dim,1);    arraY[1] = t.new_array(dim,2);
344    arraY[2] = t.new_array(dim,1);    arraY[2] = t.new_array(dim,2);
345    arraY[3] = t.new_array(dim,10);    arraY[3] = t.new_array(dim,10);
346    arraY[4] = t.new_array(dim,10);    arraY[4] = t.new_array(dim,10);
347    arraY[5] = t.new_array(dim,10);    arraY[5] = t.new_array(dim,10);
# Line 327  void TaipanTestCase::testAll() { Line 351  void TaipanTestCase::testAll() {
351    arraY[9] = t.new_array(dim,100);    arraY[9] = t.new_array(dim,100);
352    
353    assert(t.num_arrays() == 10);    assert(t.num_arrays() == 10);
354    assert(t.num_arrays(0) == 1);    assert(t.num_arrays(2) == 3);
   assert(t.num_arrays(1) == 2);  
355    assert(t.num_arrays(10) == 3);    assert(t.num_arrays(10) == 3);
356    assert(t.num_arrays(100) == 4);    assert(t.num_arrays(100) == 4);
357    assert(t.num_free(0) == 0);    assert(t.num_free(2) == 0);
   assert(t.num_free(1) == 0);  
358    assert(t.num_free(10) == 0);    assert(t.num_free(10) == 0);
359    assert(t.num_free(100) == 0);    assert(t.num_free(100) == 0);
360    assert(t.num_elements() == 432);    assert(t.num_elements() == 436);
361    
362    // delete all but the last array of each size under management    // delete all but the first array of each size under management
363    // the number of arrays under management does not change    // the number of arrays under management does not change
364    // but the number of free arrays will increase with each deallocation    // but the number of free arrays will increase with each deallocation
365      t.delete_array(arraY[1]);
366    t.delete_array(arraY[2]);    t.delete_array(arraY[2]);
367    t.delete_array(arraY[4]);    t.delete_array(arraY[4]);
368    t.delete_array(arraY[5]);    t.delete_array(arraY[5]);
# Line 348  void TaipanTestCase::testAll() { Line 371  void TaipanTestCase::testAll() {
371    t.delete_array(arraY[9]);    t.delete_array(arraY[9]);
372    
373    assert(t.num_arrays() == 10);    assert(t.num_arrays() == 10);
374    assert(t.num_arrays(0) == 1);    assert(t.num_arrays(2) == 3);
   assert(t.num_arrays(1) == 2);  
375    assert(t.num_arrays(10) == 3);    assert(t.num_arrays(10) == 3);
376    assert(t.num_arrays(100) == 4);    assert(t.num_arrays(100) == 4);
377    assert(t.num_free(0) == 0);    assert(t.num_free(2) == 2);
   assert(t.num_free(1) == 1);  
378    assert(t.num_free(10) == 2);    assert(t.num_free(10) == 2);
379    assert(t.num_free(100) == 3);    assert(t.num_free(100) == 3);
380    assert(t.num_elements() == 432);    assert(t.num_elements() == 436);
381    
382    // now reallocate the free arrays    // now reallocate the free arrays
383    // the preserved arrays will be reused    // the preserved arrays will be reused
384    // and the number of free arrays will decrease with each allocation    // and the number of free arrays will decrease with each allocation
385    arraY[2] = t.new_array(dim,1);    arraY[1] = t.new_array(dim,2);
386      arraY[2] = t.new_array(dim,2);
387    arraY[4] = t.new_array(dim,10);    arraY[4] = t.new_array(dim,10);
388    arraY[5] = t.new_array(dim,10);    arraY[5] = t.new_array(dim,10);
389    arraY[7] = t.new_array(dim,100);    arraY[7] = t.new_array(dim,100);
# Line 369  void TaipanTestCase::testAll() { Line 391  void TaipanTestCase::testAll() {
391    arraY[9] = t.new_array(dim,100);    arraY[9] = t.new_array(dim,100);
392    
393    assert(t.num_arrays() == 10);    assert(t.num_arrays() == 10);
394    assert(t.num_arrays(0) == 1);    assert(t.num_arrays(2) == 3);
   assert(t.num_arrays(1) == 2);  
395    assert(t.num_arrays(10) == 3);    assert(t.num_arrays(10) == 3);
396    assert(t.num_arrays(100) == 4);    assert(t.num_arrays(100) == 4);
397    assert(t.num_free(0) == 0);    assert(t.num_free(2) == 0);
   assert(t.num_free(1) == 0);  
398    assert(t.num_free(10) == 0);    assert(t.num_free(10) == 0);
399    assert(t.num_free(100) == 0);    assert(t.num_free(100) == 0);
400    assert(t.num_elements() == 432);    assert(t.num_elements() == 436);
401    
402    // delete all but the last array of each size under management    // delete all but the last array of each size under management
403    // the number of arrays under management does not change    // the number of arrays under management does not change
404    // but the number of free arrays will increase with each deallocation    // but the number of free arrays will increase with each deallocation
405      t.delete_array(arraY[1]);
406    t.delete_array(arraY[2]);    t.delete_array(arraY[2]);
407    t.delete_array(arraY[4]);    t.delete_array(arraY[4]);
408    t.delete_array(arraY[5]);    t.delete_array(arraY[5]);
# Line 390  void TaipanTestCase::testAll() { Line 411  void TaipanTestCase::testAll() {
411    t.delete_array(arraY[9]);    t.delete_array(arraY[9]);
412    
413    assert(t.num_arrays() == 10);    assert(t.num_arrays() == 10);
414    assert(t.num_arrays(0) == 1);    assert(t.num_arrays(2) == 3);
   assert(t.num_arrays(1) == 2);  
415    assert(t.num_arrays(10) == 3);    assert(t.num_arrays(10) == 3);
416    assert(t.num_arrays(100) == 4);    assert(t.num_arrays(100) == 4);
417    assert(t.num_free(0) == 0);    assert(t.num_free(2) == 2);
   assert(t.num_free(1) == 1);  
418    assert(t.num_free(10) == 2);    assert(t.num_free(10) == 2);
419    assert(t.num_free(100) == 3);    assert(t.num_free(100) == 3);
420    assert(t.num_elements() == 432);    assert(t.num_elements() == 436);
421    
422    // deallocate the last of the arrays    // deallocate the last of the arrays
423    t.delete_array(arraY[0]);    t.delete_array(arraY[0]);
   t.delete_array(arraY[1]);  
424    t.delete_array(arraY[3]);    t.delete_array(arraY[3]);
425    t.delete_array(arraY[6]);    t.delete_array(arraY[6]);
426    
# Line 417  TestSuite* TaipanTestCase::suite () Line 435  TestSuite* TaipanTestCase::suite ()
435    TestSuite *testSuite = new TestSuite ("TaipanTestCase");    TestSuite *testSuite = new TestSuite ("TaipanTestCase");
436    
437    testSuite->addTest (new TestCaller< TaipanTestCase>("testAll",&TaipanTestCase::testAll));    testSuite->addTest (new TestCaller< TaipanTestCase>("testAll",&TaipanTestCase::testAll));
438      testSuite->addTest (new TestCaller< TaipanTestCase>("testN1",&TaipanTestCase::testN1));
439      testSuite->addTest (new TestCaller< TaipanTestCase>("testN0",&TaipanTestCase::testN0));
440    return testSuite;    return testSuite;
441  }  }

Legend:
Removed from v.121  
changed lines
  Added in v.1388

  ViewVC Help
Powered by ViewVC 1.1.26