src/work/johanna/unionfind_test.cc
changeset 483 ce29ae5b2e1b
parent 482 dce64ce044d6
child 484 13e57edac8ed
     1.1 --- a/src/work/johanna/unionfind_test.cc	Thu Apr 29 16:59:00 2004 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,205 +0,0 @@
     1.4 -#include <iostream>
     1.5 -
     1.6 -#include <maps.h>
     1.7 -#include <unionfind.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 -typedef UnionFindEnum<int, BaseMap> UFE;
    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 -  int i = 1;
    1.30 -  for (ufe.first(cit); ufe.valid(cit); ufe.next(cit)) {
    1.31 -    cout << "  " << i << " (" << cit << "):" << flush;
    1.32 -    UFE::ItemIt iit;
    1.33 -    for (ufe.first(iit, cit); ufe.valid(iit); ufe.next(iit)) {
    1.34 -      cout << " " << iit << flush;
    1.35 -    }
    1.36 -    cout << endl;
    1.37 -    i++;
    1.38 -  }
    1.39 -  cout << "done" << endl;
    1.40 -}
    1.41 -
    1.42 -
    1.43 -int main() {
    1.44 -  UFE::MapType base;
    1.45 -  UFE U(base);
    1.46 -
    1.47 -  print(U);
    1.48 -
    1.49 -  cout << "Inserting 1..." << endl;
    1.50 -  U.insert(1);
    1.51 -  print(U);
    1.52 -  
    1.53 -  cout << "Inserting 2..." << endl;
    1.54 -  U.insert(2);
    1.55 -  print(U);
    1.56 -  
    1.57 -  cout << "Joining 1 and 2..." << endl;
    1.58 -  check(U.join(1,2));
    1.59 -  print(U);
    1.60 -
    1.61 -  cout << "Inserting 3, 4, 5, 6, 7..." << endl;
    1.62 -  U.insert(3);
    1.63 -  U.insert(4);
    1.64 -  U.insert(5);
    1.65 -  U.insert(6);
    1.66 -  U.insert(7);
    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 -
    1.75 -  cout << "Inserting 8 to the component of 5 ..." << endl;
    1.76 -  U.insert(8,5);
    1.77 -  print(U);
    1.78 -
    1.79 -  cout << "size of the class of 4: " << U.size(4) << endl;
    1.80 -  check(U.size(4) == 3);
    1.81 -  cout << "size of the class of 5: " << U.size(5) << endl;
    1.82 -  check(U.size(5) == 3);
    1.83 -  cout << "size of the class of 6: " << U.size(6) << endl;
    1.84 -  check(U.size(6) == 1);
    1.85 -  cout << "size of the class of 2: " << U.size(2) << endl;
    1.86 -  check(U.size(2) == 3);
    1.87 -
    1.88 -  cout << "Inserting 9 ..." << endl;
    1.89 -  U.insert(9);
    1.90 -  print(U);
    1.91 -  cout << "Inserting 10 to the component of 9 ..." << endl;
    1.92 -  U.insert(10,9);
    1.93 -  print(U);
    1.94 -
    1.95 -  cout << "Joining 8 and 10..." << endl;
    1.96 -  check(U.join(8,10));
    1.97 -  print(U);
    1.98 -
    1.99 -  cout << "Move 9 to the class of 4 ..." << endl;
   1.100 -  check(U.move(9,4));
   1.101 -  print(U);
   1.102 -
   1.103 -  cout << "Move 9 to the class of 2 ..." << endl;
   1.104 -  check(!U.move(9,2));
   1.105 -  print(U);
   1.106 -
   1.107 -  cout << "size of the class of 4: " << U.size(4) << endl;
   1.108 -  check(U.size(4) == 4);
   1.109 -  cout << "size of the class of 9: " << U.size(9) << endl;
   1.110 -  check(U.size(9) == 4);
   1.111 -  
   1.112 -  cout << "Move 5 to the class of 6 ..." << endl;
   1.113 -  check(U.move(5,6));
   1.114 -  print(U);
   1.115 -
   1.116 -  cout << "size of the class of 5: " << U.size(5) << endl;
   1.117 -  check(U.size(5) == 2);
   1.118 -  cout << "size of the class of 8: " << U.size(8) << endl;
   1.119 -  check(U.size(8) == 3);
   1.120 -
   1.121 -  cout << "Move 7 to the class of 10 ..." << endl;
   1.122 -  check(U.move(7,10));
   1.123 -  print(U);
   1.124 -
   1.125 -  cout << "size of the class of 7: " << U.size(7) << endl;
   1.126 -  check(U.size(7) == 4);
   1.127 -
   1.128 -  cout <<"erase 9: " << endl;
   1.129 -  U.erase(9);
   1.130 -  print(U);
   1.131 -
   1.132 -  cout <<"erase 1: " << endl;
   1.133 -  U.erase(1);
   1.134 -  print(U);
   1.135 -
   1.136 -  cout << "size of the class of 4: " << U.size(4) << endl;
   1.137 -  check(U.size(4) == 2);
   1.138 -  cout << "size of the class of 2: " << U.size(2) << endl;
   1.139 -  check(U.size(2) == 2);
   1.140 -
   1.141 -
   1.142 -  cout <<"erase 1: " << endl;
   1.143 -  U.erase(1);
   1.144 -  print(U);
   1.145 -
   1.146 -  cout <<"erase 6: " << endl;
   1.147 -  U.erase(6);
   1.148 -  print(U);
   1.149 -
   1.150 -  cout << "split the class of 8: " << endl;
   1.151 -  U.split(8);
   1.152 -  print(U);
   1.153 -
   1.154 -
   1.155 -  cout << "size of the class of 4: " << U.size(4) << endl;
   1.156 -  check(U.size(4) == 2);
   1.157 -  cout << "size of the class of 3: " << U.size(3) << endl;
   1.158 -  check(U.size(3) == 1);
   1.159 -  cout << "size of the class of 2: " << U.size(2) << endl;
   1.160 -  check(U.size(2) == 2);
   1.161 -
   1.162 -
   1.163 -  cout << "Joining 3 - 4 and 2 - 4 ..." << endl;
   1.164 -  check(U.join(3,4));
   1.165 -  check(!U.join(2,4));
   1.166 -  print(U);
   1.167 -
   1.168 -
   1.169 -  cout << "size of the class of 4: " << U.size(4) << endl;
   1.170 -  check(U.size(4) == 3);
   1.171 -  cout << "size of the class of 3: " << U.size(3) << endl;
   1.172 -  check(U.size(3) == 3);
   1.173 -  cout << "size of the class of 2: " << U.size(2) << endl;
   1.174 -  check(U.size(2) == 3);
   1.175 -
   1.176 -  cout << "makeRep(4)" << endl;
   1.177 -  U.makeRep(4);
   1.178 -  print(U);
   1.179 -  cout << "makeRep(3)" << endl;
   1.180 -  U.makeRep(3);
   1.181 -  print(U);
   1.182 -  cout << "makeRep(2)" << endl;
   1.183 -  U.makeRep(2);
   1.184 -  print(U);
   1.185 -
   1.186 -  cout << "size of the class of 4: " << U.size(4) << endl;
   1.187 -  check(U.size(4) == 3);
   1.188 -  cout << "size of the class of 3: " << U.size(3) << endl;
   1.189 -  check(U.size(3) == 3);
   1.190 -  cout << "size of the class of 2: " << U.size(2) << endl;
   1.191 -  check(U.size(2) == 3);
   1.192 -
   1.193 -
   1.194 -  cout << "eraseClass 4 ..." << endl;
   1.195 -  U.eraseClass(4);
   1.196 -  print(U);
   1.197 -
   1.198 -  cout << "eraseClass 7 ..." << endl;
   1.199 -  U.eraseClass(7);
   1.200 -  print(U);
   1.201 -
   1.202 -  cout << "done" << endl;
   1.203 -
   1.204 -  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
   1.205 -       << endl;
   1.206 -
   1.207 -  return passed ? 0 : 1;
   1.208 -}