src/test/unionfind_test.cc
changeset 774 4297098d9677
parent 542 69bde1d90c04
child 793 9cd0aeea47b0
     1.1 --- a/src/test/unionfind_test.cc	Wed Aug 25 18:55:57 2004 +0000
     1.2 +++ b/src/test/unionfind_test.cc	Mon Aug 30 12:01:47 2004 +0000
     1.3 @@ -2,19 +2,11 @@
     1.4  
     1.5  #include <hugo/maps.h>
     1.6  #include <hugo/unionfind.h>
     1.7 +#include "test_tools.h"
     1.8  
     1.9  using namespace hugo;
    1.10  using namespace std;
    1.11  
    1.12 -bool passed = true;
    1.13 -
    1.14 -void check(bool rc) {
    1.15 -  passed = passed && rc;
    1.16 -  if(!rc) {
    1.17 -    cout << "Test failed!" << endl;
    1.18 -  }
    1.19 -}
    1.20 -
    1.21  template <typename T>
    1.22  class BaseMap : public StdMap<int,T> {};
    1.23  
    1.24 @@ -22,7 +14,7 @@
    1.25  
    1.26  void print(UFE const &ufe) {
    1.27    UFE::ClassIt cit;
    1.28 -  cout << "printing the classes of the structure:" << endl;
    1.29 +  cout << "Print the classes of the structure:" << endl;
    1.30    int i = 1;
    1.31    for (ufe.first(cit); ufe.valid(cit); ufe.next(cit)) {
    1.32      cout << "  " << i << " (" << cit << "):" << flush;
    1.33 @@ -41,165 +33,160 @@
    1.34    UFE::MapType base;
    1.35    UFE U(base);
    1.36  
    1.37 -  print(U);
    1.38 +//   print(U);
    1.39  
    1.40 -  cout << "Inserting 1..." << endl;
    1.41 +  cout << "Insert 1..." << endl;
    1.42    U.insert(1);
    1.43 -  print(U);
    1.44 +//   print(U);
    1.45    
    1.46 -  cout << "Inserting 2..." << endl;
    1.47 +  cout << "Insert 2..." << endl;
    1.48    U.insert(2);
    1.49 -  print(U);
    1.50 +//   print(U);
    1.51    
    1.52 -  cout << "Joining 1 and 2..." << endl;
    1.53 -  check(U.join(1,2));
    1.54 -  print(U);
    1.55 +  cout << "Join 1 and 2..." << endl;
    1.56 +  check(U.join(1,2),"Test failed.");
    1.57 +//   print(U);
    1.58  
    1.59 -  cout << "Inserting 3, 4, 5, 6, 7..." << endl;
    1.60 +  cout << "Insert 3, 4, 5, 6, 7..." << endl;
    1.61    U.insert(3);
    1.62    U.insert(4);
    1.63    U.insert(5);
    1.64    U.insert(6);
    1.65    U.insert(7);
    1.66 -  print (U);
    1.67 +//   print (U);
    1.68  
    1.69 -  cout << "Joining 1 - 4, 2 - 4 and 3 - 5 ..." << endl;
    1.70 -  check(U.join(1,4));
    1.71 -  check(!U.join(2,4));
    1.72 -  check(U.join(3,5));
    1.73 -  print(U);
    1.74 +  cout << "Join 1 - 4, 2 - 4 and 3 - 5 ..." << endl;
    1.75 +  check(U.join(1,4),"Test failed.");
    1.76 +  check(!U.join(2,4),"Test failed.");
    1.77 +  check(U.join(3,5),"Test failed.");
    1.78 +//   print(U);
    1.79  
    1.80 -  cout << "Inserting 8 to the component of 5 ..." << endl;
    1.81 +  cout << "Insert 8 to the component of 5 ..." << endl;
    1.82    U.insert(8,5);
    1.83 -  print(U);
    1.84 +//   print(U);
    1.85  
    1.86 -  cout << "size of the class of 4: " << U.size(4) << endl;
    1.87 -  check(U.size(4) == 3);
    1.88 -  cout << "size of the class of 5: " << U.size(5) << endl;
    1.89 -  check(U.size(5) == 3);
    1.90 -  cout << "size of the class of 6: " << U.size(6) << endl;
    1.91 -  check(U.size(6) == 1);
    1.92 -  cout << "size of the class of 2: " << U.size(2) << endl;
    1.93 -  check(U.size(2) == 3);
    1.94 +  cout << "Size of the class of 4: " << U.size(4) << endl;
    1.95 +  check(U.size(4) == 3,"Test failed.");
    1.96 +  cout << "Size of the class of 5: " << U.size(5) << endl;
    1.97 +  check(U.size(5) == 3,"Test failed.");
    1.98 +  cout << "Size of the class of 6: " << U.size(6) << endl;
    1.99 +  check(U.size(6) == 1,"Test failed.");
   1.100 +  cout << "Size of the class of 2: " << U.size(2) << endl;
   1.101 +  check(U.size(2) == 3,"Test failed.");
   1.102  
   1.103 -  cout << "Inserting 9 ..." << endl;
   1.104 +  cout << "Insert 9 ..." << endl;
   1.105    U.insert(9);
   1.106 -  print(U);
   1.107 -  cout << "Inserting 10 to the component of 9 ..." << endl;
   1.108 +//   print(U);
   1.109 +  cout << "Insert 10 to the component of 9 ..." << endl;
   1.110    U.insert(10,9);
   1.111 -  print(U);
   1.112 +//   print(U);
   1.113  
   1.114 -  cout << "Joining 8 and 10..." << endl;
   1.115 -  check(U.join(8,10));
   1.116 -  print(U);
   1.117 +  cout << "Join 8 and 10..." << endl;
   1.118 +  check(U.join(8,10),"Test failed.");
   1.119 +//   print(U);
   1.120  
   1.121    cout << "Move 9 to the class of 4 ..." << endl;
   1.122 -  check(U.move(9,4));
   1.123 -  print(U);
   1.124 +  check(U.move(9,4),"Test failed.");
   1.125 +//   print(U);
   1.126  
   1.127    cout << "Move 9 to the class of 2 ..." << endl;
   1.128 -  check(!U.move(9,2));
   1.129 -  print(U);
   1.130 +  check(!U.move(9,2),"Test failed.");
   1.131 +//   print(U);
   1.132  
   1.133 -  cout << "size of the class of 4: " << U.size(4) << endl;
   1.134 -  check(U.size(4) == 4);
   1.135 -  cout << "size of the class of 9: " << U.size(9) << endl;
   1.136 -  check(U.size(9) == 4);
   1.137 +  cout << "Size of the class of 4: " << U.size(4) << endl;
   1.138 +  check(U.size(4) == 4,"Test failed.");
   1.139 +  cout << "Size of the class of 9: " << U.size(9) << endl;
   1.140 +  check(U.size(9) == 4,"Test failed.");
   1.141    
   1.142    cout << "Move 5 to the class of 6 ..." << endl;
   1.143 -  check(U.move(5,6));
   1.144 -  print(U);
   1.145 +  check(U.move(5,6),"Test failed.");
   1.146 +//   print(U);
   1.147  
   1.148 -  cout << "size of the class of 5: " << U.size(5) << endl;
   1.149 -  check(U.size(5) == 2);
   1.150 -  cout << "size of the class of 8: " << U.size(8) << endl;
   1.151 -  check(U.size(8) == 3);
   1.152 +  cout << "Size of the class of 5: " << U.size(5) << endl;
   1.153 +  check(U.size(5) == 2,"Test failed.");
   1.154 +  cout << "Size of the class of 8: " << U.size(8) << endl;
   1.155 +  check(U.size(8) == 3,"Test failed.");
   1.156  
   1.157    cout << "Move 7 to the class of 10 ..." << endl;
   1.158 -  check(U.move(7,10));
   1.159 -  print(U);
   1.160 +  check(U.move(7,10),"Test failed.");
   1.161 +//   print(U);
   1.162  
   1.163 -  cout << "size of the class of 7: " << U.size(7) << endl;
   1.164 -  check(U.size(7) == 4);
   1.165 +  cout << "Size of the class of 7: " << U.size(7) << endl;
   1.166 +  check(U.size(7) == 4,"Test failed.");
   1.167  
   1.168 -  cout <<"erase 9: " << endl;
   1.169 +  cout <<"Erase 9... " << endl;
   1.170    U.erase(9);
   1.171 -  print(U);
   1.172 +//   print(U);
   1.173  
   1.174 -  cout <<"erase 1: " << endl;
   1.175 +  cout <<"Erase 1... " << endl;
   1.176    U.erase(1);
   1.177 -  print(U);
   1.178 +//   print(U);
   1.179  
   1.180 -  cout << "size of the class of 4: " << U.size(4) << endl;
   1.181 -  check(U.size(4) == 2);
   1.182 -  cout << "size of the class of 2: " << U.size(2) << endl;
   1.183 -  check(U.size(2) == 2);
   1.184 +  cout << "Size of the class of 4: " << U.size(4) << endl;
   1.185 +  check(U.size(4) == 2,"Test failed.");
   1.186 +  cout << "Size of the class of 2: " << U.size(2) << endl;
   1.187 +  check(U.size(2) == 2,"Test failed.");
   1.188  
   1.189  
   1.190 -  cout <<"erase 1: " << endl;
   1.191 +  cout <<"Erase 1... " << endl;
   1.192    U.erase(1);
   1.193 -  print(U);
   1.194 +//   print(U);
   1.195  
   1.196 -  cout <<"erase 6: " << endl;
   1.197 +  cout <<"Erase 6... " << endl;
   1.198    U.erase(6);
   1.199 -  print(U);
   1.200 +//   print(U);
   1.201  
   1.202 -  cout << "split the class of 8: " << endl;
   1.203 +  cout << "Split the class of 8... " << endl;
   1.204    U.split(8);
   1.205 -  print(U);
   1.206 +//   print(U);
   1.207  
   1.208  
   1.209 -  cout << "size of the class of 4: " << U.size(4) << endl;
   1.210 -  check(U.size(4) == 2);
   1.211 -  cout << "size of the class of 3: " << U.size(3) << endl;
   1.212 -  check(U.size(3) == 1);
   1.213 -  cout << "size of the class of 2: " << U.size(2) << endl;
   1.214 -  check(U.size(2) == 2);
   1.215 +  cout << "Size of the class of 4: " << U.size(4) << endl;
   1.216 +  check(U.size(4) == 2,"Test failed.");
   1.217 +  cout << "Size of the class of 3: " << U.size(3) << endl;
   1.218 +  check(U.size(3) == 1,"Test failed.");
   1.219 +  cout << "Size of the class of 2: " << U.size(2) << endl;
   1.220 +  check(U.size(2) == 2,"Test failed.");
   1.221  
   1.222  
   1.223 -  cout << "Joining 3 - 4 and 2 - 4 ..." << endl;
   1.224 -  check(U.join(3,4));
   1.225 -  check(!U.join(2,4));
   1.226 -  print(U);
   1.227 +  cout << "Join 3 - 4 and 2 - 4 ..." << endl;
   1.228 +  check(U.join(3,4),"Test failed.");
   1.229 +  check(!U.join(2,4),"Test failed.");
   1.230 +//   print(U);
   1.231  
   1.232  
   1.233 -  cout << "size of the class of 4: " << U.size(4) << endl;
   1.234 -  check(U.size(4) == 3);
   1.235 -  cout << "size of the class of 3: " << U.size(3) << endl;
   1.236 -  check(U.size(3) == 3);
   1.237 -  cout << "size of the class of 2: " << U.size(2) << endl;
   1.238 -  check(U.size(2) == 3);
   1.239 +  cout << "Size of the class of 4: " << U.size(4) << endl;
   1.240 +  check(U.size(4) == 3,"Test failed.");
   1.241 +  cout << "Size of the class of 3: " << U.size(3) << endl;
   1.242 +  check(U.size(3) == 3,"Test failed.");
   1.243 +  cout << "Size of the class of 2: " << U.size(2) << endl;
   1.244 +  check(U.size(2) == 3,"Test failed.");
   1.245  
   1.246 -  cout << "makeRep(4)" << endl;
   1.247 +  cout << "makeRep(4)..." << endl;
   1.248    U.makeRep(4);
   1.249 -  print(U);
   1.250 -  cout << "makeRep(3)" << endl;
   1.251 +//   print(U);
   1.252 +  cout << "makeRep(3)..." << endl;
   1.253    U.makeRep(3);
   1.254 -  print(U);
   1.255 -  cout << "makeRep(2)" << endl;
   1.256 +//   print(U);
   1.257 +  cout << "makeRep(2)..." << endl;
   1.258    U.makeRep(2);
   1.259 -  print(U);
   1.260 +//   print(U);
   1.261  
   1.262 -  cout << "size of the class of 4: " << U.size(4) << endl;
   1.263 -  check(U.size(4) == 3);
   1.264 -  cout << "size of the class of 3: " << U.size(3) << endl;
   1.265 -  check(U.size(3) == 3);
   1.266 -  cout << "size of the class of 2: " << U.size(2) << endl;
   1.267 -  check(U.size(2) == 3);
   1.268 +  cout << "Size of the class of 4: " << U.size(4) << endl;
   1.269 +  check(U.size(4) == 3,"Test failed.");
   1.270 +  cout << "Size of the class of 3: " << U.size(3) << endl;
   1.271 +  check(U.size(3) == 3,"Test failed.");
   1.272 +  cout << "Size of the class of 2: " << U.size(2) << endl;
   1.273 +  check(U.size(2) == 3,"Test failed.");
   1.274  
   1.275  
   1.276    cout << "eraseClass 4 ..." << endl;
   1.277    U.eraseClass(4);
   1.278 -  print(U);
   1.279 +//   print(U);
   1.280  
   1.281    cout << "eraseClass 7 ..." << endl;
   1.282    U.eraseClass(7);
   1.283 -  print(U);
   1.284 +//   print(U);
   1.285  
   1.286 -  cout << "done" << endl;
   1.287 -
   1.288 -  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
   1.289 -       << endl;
   1.290 -
   1.291 -  return passed ? 0 : 1;
   1.292 +  cout << "done." << endl;
   1.293  }