... |
... |
@@ -24,16 +24,17 @@
|
24 |
24 |
#include "test_tools.h"
|
25 |
25 |
|
26 |
26 |
using namespace std;
|
27 |
27 |
using namespace lemon;
|
28 |
28 |
|
29 |
29 |
void digraph_copy_test() {
|
30 |
30 |
const int nn = 10;
|
31 |
31 |
|
|
32 |
// Build a digraph
|
32 |
33 |
SmartDigraph from;
|
33 |
34 |
SmartDigraph::NodeMap<int> fnm(from);
|
34 |
35 |
SmartDigraph::ArcMap<int> fam(from);
|
35 |
36 |
SmartDigraph::Node fn = INVALID;
|
36 |
37 |
SmartDigraph::Arc fa = INVALID;
|
37 |
38 |
|
38 |
39 |
std::vector<SmartDigraph::Node> fnv;
|
39 |
40 |
for (int i = 0; i < nn; ++i) {
|
... |
... |
@@ -46,16 +47,17 @@
|
46 |
47 |
for (int i = 0; i < nn; ++i) {
|
47 |
48 |
for (int j = 0; j < nn; ++j) {
|
48 |
49 |
SmartDigraph::Arc arc = from.addArc(fnv[i], fnv[j]);
|
49 |
50 |
fam[arc] = i + j * j;
|
50 |
51 |
if (i == 0 && j == 0) fa = arc;
|
51 |
52 |
}
|
52 |
53 |
}
|
53 |
54 |
|
|
55 |
// Test digraph copy
|
54 |
56 |
ListDigraph to;
|
55 |
57 |
ListDigraph::NodeMap<int> tnm(to);
|
56 |
58 |
ListDigraph::ArcMap<int> tam(to);
|
57 |
59 |
ListDigraph::Node tn;
|
58 |
60 |
ListDigraph::Arc ta;
|
59 |
61 |
|
60 |
62 |
SmartDigraph::NodeMap<ListDigraph::Node> nr(from);
|
61 |
63 |
SmartDigraph::ArcMap<ListDigraph::Arc> er(from);
|
... |
... |
@@ -63,16 +65,19 @@
|
63 |
65 |
ListDigraph::NodeMap<SmartDigraph::Node> ncr(to);
|
64 |
66 |
ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to);
|
65 |
67 |
|
66 |
68 |
digraphCopy(from, to).
|
67 |
69 |
nodeMap(fnm, tnm).arcMap(fam, tam).
|
68 |
70 |
nodeRef(nr).arcRef(er).
|
69 |
71 |
nodeCrossRef(ncr).arcCrossRef(ecr).
|
70 |
72 |
node(fn, tn).arc(fa, ta).run();
|
|
73 |
|
|
74 |
check(countNodes(from) == countNodes(to), "Wrong copy.");
|
|
75 |
check(countArcs(from) == countArcs(to), "Wrong copy.");
|
71 |
76 |
|
72 |
77 |
for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) {
|
73 |
78 |
check(ncr[nr[it]] == it, "Wrong copy.");
|
74 |
79 |
check(fnm[it] == tnm[nr[it]], "Wrong copy.");
|
75 |
80 |
}
|
76 |
81 |
|
77 |
82 |
for (SmartDigraph::ArcIt it(from); it != INVALID; ++it) {
|
78 |
83 |
check(ecr[er[it]] == it, "Wrong copy.");
|
... |
... |
@@ -85,21 +90,28 @@
|
85 |
90 |
check(nr[ncr[it]] == it, "Wrong copy.");
|
86 |
91 |
}
|
87 |
92 |
|
88 |
93 |
for (ListDigraph::ArcIt it(to); it != INVALID; ++it) {
|
89 |
94 |
check(er[ecr[it]] == it, "Wrong copy.");
|
90 |
95 |
}
|
91 |
96 |
check(tn == nr[fn], "Wrong copy.");
|
92 |
97 |
check(ta == er[fa], "Wrong copy.");
|
|
98 |
|
|
99 |
// Test repeated copy
|
|
100 |
digraphCopy(from, to).run();
|
|
101 |
|
|
102 |
check(countNodes(from) == countNodes(to), "Wrong copy.");
|
|
103 |
check(countArcs(from) == countArcs(to), "Wrong copy.");
|
93 |
104 |
}
|
94 |
105 |
|
95 |
106 |
void graph_copy_test() {
|
96 |
107 |
const int nn = 10;
|
97 |
108 |
|
|
109 |
// Build a graph
|
98 |
110 |
SmartGraph from;
|
99 |
111 |
SmartGraph::NodeMap<int> fnm(from);
|
100 |
112 |
SmartGraph::ArcMap<int> fam(from);
|
101 |
113 |
SmartGraph::EdgeMap<int> fem(from);
|
102 |
114 |
SmartGraph::Node fn = INVALID;
|
103 |
115 |
SmartGraph::Arc fa = INVALID;
|
104 |
116 |
SmartGraph::Edge fe = INVALID;
|
105 |
117 |
|
... |
... |
@@ -117,16 +129,17 @@
|
117 |
129 |
fem[edge] = i * i + j * j;
|
118 |
130 |
fam[from.direct(edge, true)] = i + j * j;
|
119 |
131 |
fam[from.direct(edge, false)] = i * i + j;
|
120 |
132 |
if (i == 0 && j == 0) fa = from.direct(edge, true);
|
121 |
133 |
if (i == 0 && j == 0) fe = edge;
|
122 |
134 |
}
|
123 |
135 |
}
|
124 |
136 |
|
|
137 |
// Test graph copy
|
125 |
138 |
ListGraph to;
|
126 |
139 |
ListGraph::NodeMap<int> tnm(to);
|
127 |
140 |
ListGraph::ArcMap<int> tam(to);
|
128 |
141 |
ListGraph::EdgeMap<int> tem(to);
|
129 |
142 |
ListGraph::Node tn;
|
130 |
143 |
ListGraph::Arc ta;
|
131 |
144 |
ListGraph::Edge te;
|
132 |
145 |
|
... |
... |
@@ -139,16 +152,20 @@
|
139 |
152 |
ListGraph::EdgeMap<SmartGraph::Edge> ecr(to);
|
140 |
153 |
|
141 |
154 |
graphCopy(from, to).
|
142 |
155 |
nodeMap(fnm, tnm).arcMap(fam, tam).edgeMap(fem, tem).
|
143 |
156 |
nodeRef(nr).arcRef(ar).edgeRef(er).
|
144 |
157 |
nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr).
|
145 |
158 |
node(fn, tn).arc(fa, ta).edge(fe, te).run();
|
146 |
159 |
|
|
160 |
check(countNodes(from) == countNodes(to), "Wrong copy.");
|
|
161 |
check(countEdges(from) == countEdges(to), "Wrong copy.");
|
|
162 |
check(countArcs(from) == countArcs(to), "Wrong copy.");
|
|
163 |
|
147 |
164 |
for (SmartGraph::NodeIt it(from); it != INVALID; ++it) {
|
148 |
165 |
check(ncr[nr[it]] == it, "Wrong copy.");
|
149 |
166 |
check(fnm[it] == tnm[nr[it]], "Wrong copy.");
|
150 |
167 |
}
|
151 |
168 |
|
152 |
169 |
for (SmartGraph::ArcIt it(from); it != INVALID; ++it) {
|
153 |
170 |
check(acr[ar[it]] == it, "Wrong copy.");
|
154 |
171 |
check(fam[it] == tam[ar[it]], "Wrong copy.");
|
... |
... |
@@ -175,16 +192,23 @@
|
175 |
192 |
check(ar[acr[it]] == it, "Wrong copy.");
|
176 |
193 |
}
|
177 |
194 |
for (ListGraph::EdgeIt it(to); it != INVALID; ++it) {
|
178 |
195 |
check(er[ecr[it]] == it, "Wrong copy.");
|
179 |
196 |
}
|
180 |
197 |
check(tn == nr[fn], "Wrong copy.");
|
181 |
198 |
check(ta == ar[fa], "Wrong copy.");
|
182 |
199 |
check(te == er[fe], "Wrong copy.");
|
|
200 |
|
|
201 |
// Test repeated copy
|
|
202 |
graphCopy(from, to).run();
|
|
203 |
|
|
204 |
check(countNodes(from) == countNodes(to), "Wrong copy.");
|
|
205 |
check(countEdges(from) == countEdges(to), "Wrong copy.");
|
|
206 |
check(countArcs(from) == countArcs(to), "Wrong copy.");
|
183 |
207 |
}
|
184 |
208 |
|
185 |
209 |
|
186 |
210 |
int main() {
|
187 |
211 |
digraph_copy_test();
|
188 |
212 |
graph_copy_test();
|
189 |
213 |
|
190 |
214 |
return 0;
|