/[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

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

Legend:
Removed from v.150  
changed lines
  Added in v.151

  ViewVC Help
Powered by ViewVC 1.1.26