1 #include <lemon/smart_graph.h>
2 #include <lemon/list_graph.h>
3 #include <lemon/graph_reader.h>
4 #include <lemon/graph_utils.h>
5 #include <lemon/error.h>
7 #include "test_tools.h"
10 using namespace lemon;
12 void graph_copy_test() {
16 SmartGraph::NodeMap<int> snm(source);
17 SmartGraph::EdgeMap<int> sem(source);
18 SmartGraph::Node sn = INVALID;
19 SmartGraph::Edge se = INVALID;
21 std::vector<SmartGraph::Node> snv;
22 for (int i = 0; i < nn; ++i) {
23 SmartGraph::Node node = source.addNode();
26 if (i == 0) sn = node;
29 for (int i = 0; i < nn; ++i) {
30 for (int j = 0; j < nn; ++j) {
31 SmartGraph::Edge edge = source.addEdge(snv[i], snv[j]);
32 sem[edge] = i + j * j;
33 if (i == 0 && j == 0) se = edge;
38 ListGraph::NodeMap<int> tnm(target);
39 ListGraph::EdgeMap<int> tem(target);
43 SmartGraph::NodeMap<ListGraph::Node> nr(source);
44 SmartGraph::EdgeMap<ListGraph::Edge> er(source);
46 ListGraph::NodeMap<SmartGraph::Node> ncr(target);
47 ListGraph::EdgeMap<SmartGraph::Edge> ecr(target);
49 GraphCopy<ListGraph, SmartGraph>(target, source).
50 nodeMap(tnm, snm).edgeMap(tem, sem).
51 nodeRef(nr).edgeRef(er).
52 nodeCrossRef(ncr).edgeCrossRef(ecr).
53 node(tn, sn).edge(te, se).run();
55 for (SmartGraph::NodeIt it(source); it != INVALID; ++it) {
56 check(ncr[nr[it]] == it, "Wrong copy.");
57 check(snm[it] == tnm[nr[it]], "Wrong copy.");
60 for (SmartGraph::EdgeIt it(source); it != INVALID; ++it) {
61 check(ecr[er[it]] == it, "Wrong copy.");
62 check(sem[it] == tem[er[it]], "Wrong copy.");
63 check(nr[source.source(it)] ==
64 target.source(er[it]), "Wrong copy.");
65 check(nr[source.target(it)] ==
66 target.target(er[it]), "Wrong copy.");
69 for (ListGraph::NodeIt it(target); it != INVALID; ++it) {
70 check(nr[ncr[it]] == it, "Wrong copy.");
73 for (ListGraph::EdgeIt it(target); it != INVALID; ++it) {
74 check(er[ecr[it]] == it, "Wrong copy.");
76 check(tn == nr[sn], "Wrong copy.");
77 check(te == er[se], "Wrong copy.");
80 void ugraph_copy_test() {
84 SmartUGraph::NodeMap<int> snm(source);
85 SmartUGraph::EdgeMap<int> sem(source);
86 SmartUGraph::UEdgeMap<int> suem(source);
87 SmartUGraph::Node sn = INVALID;
88 SmartUGraph::Edge se = INVALID;
89 SmartUGraph::UEdge sue = INVALID;
91 std::vector<SmartGraph::Node> snv;
92 for (int i = 0; i < nn; ++i) {
93 SmartUGraph::Node node = source.addNode();
96 if (i == 0) sn = node;
99 for (int i = 0; i < nn; ++i) {
100 for (int j = 0; j < nn; ++j) {
101 SmartUGraph::UEdge edge = source.addEdge(snv[i], snv[j]);
102 suem[edge] = i * i + j * j;
103 sem[source.direct(edge, true)] = i + j * j;
104 sem[source.direct(edge, false)] = i * i + j;
105 if (i == 0 && j == 0) se = source.direct(edge, true);
106 if (i == 0 && j == 0) sue = edge;
111 ListUGraph::NodeMap<int> tnm(target);
112 ListUGraph::EdgeMap<int> tem(target);
113 ListUGraph::UEdgeMap<int> tuem(target);
116 ListUGraph::UEdge tue;
118 SmartUGraph::NodeMap<ListUGraph::Node> nr(source);
119 SmartUGraph::EdgeMap<ListUGraph::Edge> er(source);
120 SmartUGraph::UEdgeMap<ListUGraph::UEdge> uer(source);
122 ListUGraph::NodeMap<SmartUGraph::Node> ncr(target);
123 ListUGraph::EdgeMap<SmartUGraph::Edge> ecr(target);
124 ListUGraph::UEdgeMap<SmartUGraph::UEdge> uecr(target);
126 UGraphCopy<ListUGraph, SmartUGraph>(target, source).
127 nodeMap(tnm, snm).edgeMap(tem, sem).uEdgeMap(tuem, suem).
128 nodeRef(nr).edgeRef(er).uEdgeRef(uer).
129 nodeCrossRef(ncr).edgeCrossRef(ecr).uEdgeCrossRef(uecr).
130 node(tn, sn).edge(te, se).uEdge(tue, sue).run();
132 for (SmartUGraph::NodeIt it(source); it != INVALID; ++it) {
133 check(ncr[nr[it]] == it, "Wrong copy.");
134 check(snm[it] == tnm[nr[it]], "Wrong copy.");
137 for (SmartUGraph::EdgeIt it(source); it != INVALID; ++it) {
138 check(ecr[er[it]] == it, "Wrong copy.");
139 check(sem[it] == tem[er[it]], "Wrong copy.");
140 check(nr[source.source(it)] ==
141 target.source(er[it]), "Wrong copy.");
142 check(nr[source.target(it)] ==
143 target.target(er[it]), "Wrong copy.");
146 for (SmartUGraph::UEdgeIt it(source); it != INVALID; ++it) {
147 check(uecr[uer[it]] == it, "Wrong copy.");
148 check(suem[it] == tuem[uer[it]], "Wrong copy.");
149 check(nr[source.source(it)] == target.source(uer[it]) ||
150 nr[source.source(it)] == target.target(uer[it]),
152 check(nr[source.target(it)] == target.source(uer[it]) ||
153 nr[source.target(it)] == target.target(uer[it]),
155 check((source.source(it) != source.target(it)) ==
156 (target.source(uer[it]) != target.target(uer[it])),
160 for (ListUGraph::NodeIt it(target); it != INVALID; ++it) {
161 check(nr[ncr[it]] == it, "Wrong copy.");
164 for (ListUGraph::EdgeIt it(target); it != INVALID; ++it) {
165 check(er[ecr[it]] == it, "Wrong copy.");
167 for (ListUGraph::UEdgeIt it(target); it != INVALID; ++it) {
168 check(uer[uecr[it]] == it, "Wrong copy.");
170 check(tn == nr[sn], "Wrong copy.");
171 check(te == er[se], "Wrong copy.");
172 check(tue == uer[sue], "Wrong copy.");
175 void bpugraph_copy_test() {
178 SmartBpUGraph source;
179 SmartBpUGraph::ANodeMap<int> sanm(source);
180 SmartBpUGraph::BNodeMap<int> sbnm(source);
181 SmartBpUGraph::NodeMap<int> snm(source);
182 SmartBpUGraph::EdgeMap<int> sem(source);
183 SmartBpUGraph::UEdgeMap<int> suem(source);
184 SmartBpUGraph::Node sn = INVALID;
185 SmartBpUGraph::Edge se = INVALID;
186 SmartBpUGraph::UEdge sue = INVALID;
188 std::vector<SmartBpUGraph::Node> sanv;
189 for (int i = 0; i < nn; ++i) {
190 SmartBpUGraph::Node node = source.addANode();
191 sanv.push_back(node);
193 snm[node] = i * i + i;
194 if (i == 0) sn = node;
197 std::vector<SmartBpUGraph::Node> sbnv;
198 for (int i = 0; i < nn; ++i) {
199 SmartBpUGraph::Node node = source.addBNode();
200 sbnv.push_back(node);
201 sbnm[node] = i * i - i;
202 snm[node] = i * i + i + 1;
205 for (int i = 0; i < nn; ++i) {
206 for (int j = 0; j < nn; ++j) {
207 SmartBpUGraph::UEdge edge = source.addEdge(sanv[i], sbnv[j]);
208 suem[edge] = i * i + j * j;
209 sem[source.direct(edge, true)] = i + j * j;
210 sem[source.direct(edge, false)] = i * i + j;
211 if (i == 0 && j == 0) se = source.direct(edge, true);
212 if (i == 0 && j == 0) sue = edge;
217 ListBpUGraph::ANodeMap<int> tanm(target);
218 ListBpUGraph::BNodeMap<int> tbnm(target);
219 ListBpUGraph::NodeMap<int> tnm(target);
220 ListBpUGraph::EdgeMap<int> tem(target);
221 ListBpUGraph::UEdgeMap<int> tuem(target);
222 ListBpUGraph::Node tn;
223 ListBpUGraph::Edge te;
224 ListBpUGraph::UEdge tue;
226 SmartBpUGraph::ANodeMap<ListBpUGraph::Node> anr(source);
227 SmartBpUGraph::BNodeMap<ListBpUGraph::Node> bnr(source);
228 SmartBpUGraph::NodeMap<ListBpUGraph::Node> nr(source);
229 SmartBpUGraph::EdgeMap<ListBpUGraph::Edge> er(source);
230 SmartBpUGraph::UEdgeMap<ListBpUGraph::UEdge> uer(source);
232 ListBpUGraph::ANodeMap<SmartBpUGraph::Node> ancr(target);
233 ListBpUGraph::BNodeMap<SmartBpUGraph::Node> bncr(target);
234 ListBpUGraph::NodeMap<SmartBpUGraph::Node> ncr(target);
235 ListBpUGraph::EdgeMap<SmartBpUGraph::Edge> ecr(target);
236 ListBpUGraph::UEdgeMap<SmartBpUGraph::UEdge> uecr(target);
238 BpUGraphCopy<ListBpUGraph, SmartBpUGraph>(target, source).
239 aNodeMap(tanm, sanm).bNodeMap(tbnm, sbnm).nodeMap(tnm, snm).
240 edgeMap(tem, sem).uEdgeMap(tuem, suem).
241 aNodeRef(anr).bNodeRef(bnr).nodeRef(nr).edgeRef(er).uEdgeRef(uer).
242 aNodeCrossRef(ancr).bNodeCrossRef(bncr).nodeCrossRef(ncr).
243 edgeCrossRef(ecr).uEdgeCrossRef(uecr).
244 node(tn, sn).edge(te, se).uEdge(tue, sue).run();
246 for (SmartBpUGraph::ANodeIt it(source); it != INVALID; ++it) {
247 check(nr[it] == anr[it], "Wrong copy.");
248 check(ancr[anr[it]] == it, "Wrong copy.");
249 check(sanm[it] == tanm[anr[it]], "Wrong copy.");
252 for (SmartBpUGraph::BNodeIt it(source); it != INVALID; ++it) {
253 check(nr[it] == bnr[it], "Wrong copy.");
254 check(bncr[bnr[it]] == it, "Wrong copy.");
255 check(sbnm[it] == tbnm[bnr[it]], "Wrong copy.");
258 for (SmartBpUGraph::NodeIt it(source); it != INVALID; ++it) {
259 check(ncr[nr[it]] == it, "Wrong copy.");
260 check(snm[it] == tnm[nr[it]], "Wrong copy.");
263 for (SmartBpUGraph::EdgeIt it(source); it != INVALID; ++it) {
264 check(ecr[er[it]] == it, "Wrong copy.");
265 check(sem[it] == tem[er[it]], "Wrong copy.");
266 check(nr[source.source(it)] ==
267 target.source(er[it]), "Wrong copy.");
268 check(nr[source.target(it)] ==
269 target.target(er[it]), "Wrong copy.");
272 for (SmartBpUGraph::UEdgeIt it(source); it != INVALID; ++it) {
273 check(uecr[uer[it]] == it, "Wrong copy.");
274 check(suem[it] == tuem[uer[it]], "Wrong copy.");
275 check(nr[source.aNode(it)] ==
276 target.aNode(uer[it]), "Wrong copy.");
277 check(nr[source.bNode(it)] ==
278 target.bNode(uer[it]), "Wrong copy.");
281 for (ListBpUGraph::ANodeIt it(target); it != INVALID; ++it) {
282 check(ancr[it] == ncr[it], "Wrong copy.");
283 check(anr[ancr[it]] == it, "Wrong copy.");
286 for (ListBpUGraph::BNodeIt it(target); it != INVALID; ++it) {
287 check(bncr[it] == ncr[it], "Wrong copy.");
288 check(bnr[bncr[it]] == it, "Wrong copy.");
291 for (ListBpUGraph::NodeIt it(target); it != INVALID; ++it) {
292 check(nr[ncr[it]] == it, "Wrong copy.");
295 for (ListBpUGraph::EdgeIt it(target); it != INVALID; ++it) {
296 check(er[ecr[it]] == it, "Wrong copy.");
298 for (ListBpUGraph::UEdgeIt it(target); it != INVALID; ++it) {
299 check(uer[uecr[it]] == it, "Wrong copy.");
301 check(tn == nr[sn], "Wrong copy.");
302 check(te == er[se], "Wrong copy.");
303 check(tue == uer[sue], "Wrong copy.");
309 bpugraph_copy_test();