... | ... |
@@ -9,106 +9,96 @@ |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#include <iostream> |
20 | 20 |
|
21 |
#include <lemon/list_graph.h> |
|
21 | 22 |
#include <lemon/maps.h> |
22 | 23 |
#include <lemon/unionfind.h> |
23 | 24 |
#include "test_tools.h" |
24 | 25 |
|
25 | 26 |
using namespace lemon; |
26 | 27 |
using namespace std; |
27 | 28 |
|
28 |
typedef UnionFindEnum<StdMap<int, int> > UFE; |
|
29 |
|
|
30 |
void print(UFE const &ufe) { |
|
31 |
cout << "Print the classes of the structure:" << endl; |
|
32 |
int i = 1; |
|
33 |
for (UFE::ClassIt cit(ufe); cit != INVALID; ++cit) { |
|
34 |
cout << " " << i << " (" << cit << "):" << flush; |
|
35 |
for (UFE::ItemIt iit(ufe, cit); iit != INVALID; ++iit) { |
|
36 |
cout << " " << iit << flush; |
|
37 |
} |
|
38 |
cout << endl; |
|
39 |
i++; |
|
40 |
} |
|
41 |
cout << "done" << endl; |
|
42 |
} |
|
43 |
|
|
29 |
typedef UnionFindEnum<ListGraph::NodeMap<int> > UFE; |
|
44 | 30 |
|
45 | 31 |
int main() { |
46 |
|
|
32 |
ListGraph g; |
|
33 |
ListGraph::NodeMap<int> base(g); |
|
47 | 34 |
UFE U(base); |
35 |
vector<ListGraph::Node> n; |
|
48 | 36 |
|
49 |
U.insert(1); |
|
50 |
U.insert(2); |
|
37 |
for(int i=0;i<20;i++) n.push_back(g.addNode()); |
|
51 | 38 |
|
52 |
|
|
39 |
U.insert(n[1]); |
|
40 |
U.insert(n[2]); |
|
53 | 41 |
|
54 |
U.insert(3); |
|
55 |
U.insert(4); |
|
56 |
U.insert(5); |
|
57 |
U.insert(6); |
|
58 |
U. |
|
42 |
check(U.join(n[1],n[2]) != -1,"Test failed."); |
|
59 | 43 |
|
44 |
U.insert(n[3]); |
|
45 |
U.insert(n[4]); |
|
46 |
U.insert(n[5]); |
|
47 |
U.insert(n[6]); |
|
48 |
U.insert(n[7]); |
|
60 | 49 |
|
61 |
check(U.join(1,4) != -1,"Test failed."); |
|
62 |
check(U.join(2,4) == -1,"Test failed."); |
|
63 |
check(U.join(3,5) != -1,"Test failed."); |
|
64 | 50 |
|
51 |
check(U.join(n[1],n[4]) != -1,"Test failed."); |
|
52 |
check(U.join(n[2],n[4]) == -1,"Test failed."); |
|
53 |
check(U.join(n[3],n[5]) != -1,"Test failed."); |
|
65 | 54 |
|
66 |
U.insert(8,U.find(5)); |
|
67 | 55 |
|
56 |
U.insert(n[8],U.find(n[5])); |
|
68 | 57 |
|
69 |
check(U.size(U.find(4)) == 3,"Test failed."); |
|
70 |
check(U.size(U.find(5)) == 3,"Test failed."); |
|
71 |
check(U.size(U.find(6)) == 1,"Test failed."); |
|
72 |
check(U.size(U.find(2)) == 3,"Test failed."); |
|
73 | 58 |
|
59 |
check(U.size(U.find(n[4])) == 3,"Test failed."); |
|
60 |
check(U.size(U.find(n[5])) == 3,"Test failed."); |
|
61 |
check(U.size(U.find(n[6])) == 1,"Test failed."); |
|
62 |
check(U.size(U.find(n[2])) == 3,"Test failed."); |
|
74 | 63 |
|
75 |
U.insert(9); |
|
76 |
U.insert(10,U.find(9)); |
|
77 | 64 |
|
65 |
U.insert(n[9]); |
|
66 |
U.insert(n[10],U.find(n[9])); |
|
78 | 67 |
|
79 |
check(U.join(8,10) != -1,"Test failed."); |
|
80 | 68 |
|
69 |
check(U.join(n[8],n[10]) != -1,"Test failed."); |
|
81 | 70 |
|
82 |
check(U.size(U.find(4)) == 3,"Test failed."); |
|
83 |
check(U.size(U.find(9)) == 5,"Test failed."); |
|
84 | 71 |
|
85 |
check(U.size(U.find( |
|
72 |
check(U.size(U.find(n[4])) == 3,"Test failed."); |
|
73 |
check(U.size(U.find(n[9])) == 5,"Test failed."); |
|
86 | 74 |
|
87 |
U.erase(9); |
|
88 |
U.erase(1); |
|
75 |
check(U.size(U.find(n[8])) == 5,"Test failed."); |
|
89 | 76 |
|
90 |
check(U.size(U.find(10)) == 4,"Test failed."); |
|
91 |
check(U.size(U.find(2)) == 2,"Test failed."); |
|
77 |
U.erase(n[9]); |
|
78 |
U.erase(n[1]); |
|
92 | 79 |
|
93 |
U.erase(6); |
|
94 |
U.split(U.find(8)); |
|
80 |
check(U.size(U.find(n[10])) == 4,"Test failed."); |
|
81 |
check(U.size(U.find(n[2])) == 2,"Test failed."); |
|
95 | 82 |
|
83 |
U.erase(n[6]); |
|
84 |
U.split(U.find(n[8])); |
|
96 | 85 |
|
97 |
check(U.size(U.find(4)) == 2,"Test failed."); |
|
98 |
check(U.size(U.find(3)) == 1,"Test failed."); |
|
99 |
check(U.size(U.find(2)) == 2,"Test failed."); |
|
100 | 86 |
|
87 |
check(U.size(U.find(n[4])) == 2,"Test failed."); |
|
88 |
check(U.size(U.find(n[3])) == 1,"Test failed."); |
|
89 |
check(U.size(U.find(n[2])) == 2,"Test failed."); |
|
101 | 90 |
|
102 |
check(U.join(3,4) != -1,"Test failed."); |
|
103 |
check(U.join(2,4) == -1,"Test failed."); |
|
104 | 91 |
|
92 |
check(U.join(n[3],n[4]) != -1,"Test failed."); |
|
93 |
check(U.join(n[2],n[4]) == -1,"Test failed."); |
|
105 | 94 |
|
106 |
check(U.size(U.find(4)) == 3,"Test failed."); |
|
107 |
check(U.size(U.find(3)) == 3,"Test failed."); |
|
108 |
check(U.size(U.find(2)) == 3,"Test failed."); |
|
109 | 95 |
|
110 |
U.eraseClass(U.find(4)); |
|
111 |
U.eraseClass(U.find(7)); |
|
96 |
check(U.size(U.find(n[4])) == 3,"Test failed."); |
|
97 |
check(U.size(U.find(n[3])) == 3,"Test failed."); |
|
98 |
check(U.size(U.find(n[2])) == 3,"Test failed."); |
|
99 |
|
|
100 |
U.eraseClass(U.find(n[4])); |
|
101 |
U.eraseClass(U.find(n[7])); |
|
112 | 102 |
|
113 | 103 |
return 0; |
114 | 104 |
} |
0 comments (0 inline)