COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/unionfind_test.cc @ 801:48638058e188

Last change on this file since 801:48638058e188 was 793:9cd0aeea47b0, checked in by Alpar Juttner, 20 years ago
  • BFD/DFS/Dijkstra compile test is done with skeleton::GraphSkeleton? graph and skeleton::ReadMap?.
  • 'skeleton::' is explicitely written instead of 'using namespace ...' in graph_test.cc
  • Output messages of type "makeRep(3)..." in unionfind_test.cc have been changed in order not to confuse compiler output parsers.
File size: 4.8 KB
RevLine 
[483]1#include <iostream>
2
[542]3#include <hugo/maps.h>
4#include <hugo/unionfind.h>
[774]5#include "test_tools.h"
[483]6
7using namespace hugo;
8using namespace std;
9
10template <typename T>
11class BaseMap : public StdMap<int,T> {};
12
13typedef UnionFindEnum<int, BaseMap> UFE;
14
15void print(UFE const &ufe) {
16  UFE::ClassIt cit;
[774]17  cout << "Print the classes of the structure:" << endl;
[483]18  int i = 1;
19  for (ufe.first(cit); ufe.valid(cit); ufe.next(cit)) {
20    cout << "  " << i << " (" << cit << "):" << flush;
21    UFE::ItemIt iit;
22    for (ufe.first(iit, cit); ufe.valid(iit); ufe.next(iit)) {
23      cout << " " << iit << flush;
24    }
25    cout << endl;
26    i++;
27  }
28  cout << "done" << endl;
29}
30
31
32int main() {
33  UFE::MapType base;
34  UFE U(base);
35
[774]36//   print(U);
[483]37
[774]38  cout << "Insert 1..." << endl;
[483]39  U.insert(1);
[774]40//   print(U);
[483]41 
[774]42  cout << "Insert 2..." << endl;
[483]43  U.insert(2);
[774]44//   print(U);
[483]45 
[774]46  cout << "Join 1 and 2..." << endl;
47  check(U.join(1,2),"Test failed.");
48//   print(U);
[483]49
[774]50  cout << "Insert 3, 4, 5, 6, 7..." << endl;
[483]51  U.insert(3);
52  U.insert(4);
53  U.insert(5);
54  U.insert(6);
55  U.insert(7);
[774]56//   print (U);
[483]57
[774]58  cout << "Join 1 - 4, 2 - 4 and 3 - 5 ..." << endl;
59  check(U.join(1,4),"Test failed.");
60  check(!U.join(2,4),"Test failed.");
61  check(U.join(3,5),"Test failed.");
62//   print(U);
[483]63
[774]64  cout << "Insert 8 to the component of 5 ..." << endl;
[483]65  U.insert(8,5);
[774]66//   print(U);
[483]67
[774]68  cout << "Size of the class of 4: " << U.size(4) << endl;
69  check(U.size(4) == 3,"Test failed.");
70  cout << "Size of the class of 5: " << U.size(5) << endl;
71  check(U.size(5) == 3,"Test failed.");
72  cout << "Size of the class of 6: " << U.size(6) << endl;
73  check(U.size(6) == 1,"Test failed.");
74  cout << "Size of the class of 2: " << U.size(2) << endl;
75  check(U.size(2) == 3,"Test failed.");
[483]76
[774]77  cout << "Insert 9 ..." << endl;
[483]78  U.insert(9);
[774]79//   print(U);
80  cout << "Insert 10 to the component of 9 ..." << endl;
[483]81  U.insert(10,9);
[774]82//   print(U);
[483]83
[774]84  cout << "Join 8 and 10..." << endl;
85  check(U.join(8,10),"Test failed.");
86//   print(U);
[483]87
88  cout << "Move 9 to the class of 4 ..." << endl;
[774]89  check(U.move(9,4),"Test failed.");
90//   print(U);
[483]91
92  cout << "Move 9 to the class of 2 ..." << endl;
[774]93  check(!U.move(9,2),"Test failed.");
94//   print(U);
[483]95
[774]96  cout << "Size of the class of 4: " << U.size(4) << endl;
97  check(U.size(4) == 4,"Test failed.");
98  cout << "Size of the class of 9: " << U.size(9) << endl;
99  check(U.size(9) == 4,"Test failed.");
[483]100 
101  cout << "Move 5 to the class of 6 ..." << endl;
[774]102  check(U.move(5,6),"Test failed.");
103//   print(U);
[483]104
[774]105  cout << "Size of the class of 5: " << U.size(5) << endl;
106  check(U.size(5) == 2,"Test failed.");
107  cout << "Size of the class of 8: " << U.size(8) << endl;
108  check(U.size(8) == 3,"Test failed.");
[483]109
110  cout << "Move 7 to the class of 10 ..." << endl;
[774]111  check(U.move(7,10),"Test failed.");
112//   print(U);
[483]113
[774]114  cout << "Size of the class of 7: " << U.size(7) << endl;
115  check(U.size(7) == 4,"Test failed.");
[483]116
[774]117  cout <<"Erase 9... " << endl;
[483]118  U.erase(9);
[774]119//   print(U);
[483]120
[774]121  cout <<"Erase 1... " << endl;
[483]122  U.erase(1);
[774]123//   print(U);
[483]124
[774]125  cout << "Size of the class of 4: " << U.size(4) << endl;
126  check(U.size(4) == 2,"Test failed.");
127  cout << "Size of the class of 2: " << U.size(2) << endl;
128  check(U.size(2) == 2,"Test failed.");
[483]129
130
[774]131  cout <<"Erase 1... " << endl;
[483]132  U.erase(1);
[774]133//   print(U);
[483]134
[774]135  cout <<"Erase 6... " << endl;
[483]136  U.erase(6);
[774]137//   print(U);
[483]138
[774]139  cout << "Split the class of 8... " << endl;
[483]140  U.split(8);
[774]141//   print(U);
[483]142
143
[774]144  cout << "Size of the class of 4: " << U.size(4) << endl;
145  check(U.size(4) == 2,"Test failed.");
146  cout << "Size of the class of 3: " << U.size(3) << endl;
147  check(U.size(3) == 1,"Test failed.");
148  cout << "Size of the class of 2: " << U.size(2) << endl;
149  check(U.size(2) == 2,"Test failed.");
[483]150
151
[774]152  cout << "Join 3 - 4 and 2 - 4 ..." << endl;
153  check(U.join(3,4),"Test failed.");
154  check(!U.join(2,4),"Test failed.");
155//   print(U);
[483]156
157
[774]158  cout << "Size of the class of 4: " << U.size(4) << endl;
159  check(U.size(4) == 3,"Test failed.");
160  cout << "Size of the class of 3: " << U.size(3) << endl;
161  check(U.size(3) == 3,"Test failed.");
162  cout << "Size of the class of 2: " << U.size(2) << endl;
163  check(U.size(2) == 3,"Test failed.");
[483]164
[793]165  cout << "Calling makeRep(4)..." << endl;
[483]166  U.makeRep(4);
[774]167//   print(U);
[793]168  cout << "Calling makeRep(3)..." << endl;
[483]169  U.makeRep(3);
[774]170//   print(U);
[793]171  cout << "Calling makeRep(2)..." << endl;
[483]172  U.makeRep(2);
[774]173//   print(U);
[483]174
[774]175  cout << "Size of the class of 4: " << U.size(4) << endl;
176  check(U.size(4) == 3,"Test failed.");
177  cout << "Size of the class of 3: " << U.size(3) << endl;
178  check(U.size(3) == 3,"Test failed.");
179  cout << "Size of the class of 2: " << U.size(2) << endl;
180  check(U.size(2) == 3,"Test failed.");
[483]181
182
183  cout << "eraseClass 4 ..." << endl;
184  U.eraseClass(4);
[774]185//   print(U);
[483]186
187  cout << "eraseClass 7 ..." << endl;
188  U.eraseClass(7);
[774]189//   print(U);
[483]190
[774]191  cout << "done." << endl;
[483]192}
Note: See TracBrowser for help on using the repository browser.