1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/graph_copy_test.cc Fri Nov 03 14:20:24 2006 +0000
1.3 @@ -0,0 +1,312 @@
1.4 +#include <lemon/smart_graph.h>
1.5 +#include <lemon/list_graph.h>
1.6 +#include <lemon/graph_reader.h>
1.7 +#include <lemon/graph_utils.h>
1.8 +#include <lemon/error.h>
1.9 +
1.10 +#include "test_tools.h"
1.11 +
1.12 +using namespace std;
1.13 +using namespace lemon;
1.14 +
1.15 +void graph_copy_test() {
1.16 + const int nn = 10;
1.17 +
1.18 + SmartGraph source;
1.19 + SmartGraph::NodeMap<int> snm(source);
1.20 + SmartGraph::EdgeMap<int> sem(source);
1.21 + SmartGraph::Node sn = INVALID;
1.22 + SmartGraph::Edge se = INVALID;
1.23 +
1.24 + std::vector<SmartGraph::Node> snv;
1.25 + for (int i = 0; i < nn; ++i) {
1.26 + SmartGraph::Node node = source.addNode();
1.27 + snv.push_back(node);
1.28 + snm[node] = i * i;
1.29 + if (i == 0) sn = node;
1.30 + }
1.31 +
1.32 + for (int i = 0; i < nn; ++i) {
1.33 + for (int j = 0; j < nn; ++j) {
1.34 + SmartGraph::Edge edge = source.addEdge(snv[i], snv[j]);
1.35 + sem[edge] = i + j * j;
1.36 + if (i == 0 && j == 0) se = edge;
1.37 + }
1.38 + }
1.39 +
1.40 + ListGraph target;
1.41 + ListGraph::NodeMap<int> tnm(target);
1.42 + ListGraph::EdgeMap<int> tem(target);
1.43 + ListGraph::Node tn;
1.44 + ListGraph::Edge te;
1.45 +
1.46 + SmartGraph::NodeMap<ListGraph::Node> nr(source);
1.47 + SmartGraph::EdgeMap<ListGraph::Edge> er(source);
1.48 +
1.49 + ListGraph::NodeMap<SmartGraph::Node> ncr(target);
1.50 + ListGraph::EdgeMap<SmartGraph::Edge> ecr(target);
1.51 +
1.52 + GraphCopy<ListGraph, SmartGraph>(target, source).
1.53 + nodeMap(tnm, snm).edgeMap(tem, sem).
1.54 + nodeRef(nr).edgeRef(er).
1.55 + nodeCrossRef(ncr).edgeCrossRef(ecr).
1.56 + node(tn, sn).edge(te, se).run();
1.57 +
1.58 + for (SmartGraph::NodeIt it(source); it != INVALID; ++it) {
1.59 + check(ncr[nr[it]] == it, "Wrong copy.");
1.60 + check(snm[it] == tnm[nr[it]], "Wrong copy.");
1.61 + }
1.62 +
1.63 + for (SmartGraph::EdgeIt it(source); it != INVALID; ++it) {
1.64 + check(ecr[er[it]] == it, "Wrong copy.");
1.65 + check(sem[it] == tem[er[it]], "Wrong copy.");
1.66 + check(nr[source.source(it)] ==
1.67 + target.source(er[it]), "Wrong copy.");
1.68 + check(nr[source.target(it)] ==
1.69 + target.target(er[it]), "Wrong copy.");
1.70 + }
1.71 +
1.72 + for (ListGraph::NodeIt it(target); it != INVALID; ++it) {
1.73 + check(nr[ncr[it]] == it, "Wrong copy.");
1.74 + }
1.75 +
1.76 + for (ListGraph::EdgeIt it(target); it != INVALID; ++it) {
1.77 + check(er[ecr[it]] == it, "Wrong copy.");
1.78 + }
1.79 + check(tn == nr[sn], "Wrong copy.");
1.80 + check(te == er[se], "Wrong copy.");
1.81 +}
1.82 +
1.83 +void ugraph_copy_test() {
1.84 + const int nn = 10;
1.85 +
1.86 + SmartUGraph source;
1.87 + SmartUGraph::NodeMap<int> snm(source);
1.88 + SmartUGraph::EdgeMap<int> sem(source);
1.89 + SmartUGraph::UEdgeMap<int> suem(source);
1.90 + SmartUGraph::Node sn = INVALID;
1.91 + SmartUGraph::Edge se = INVALID;
1.92 + SmartUGraph::UEdge sue = INVALID;
1.93 +
1.94 + std::vector<SmartGraph::Node> snv;
1.95 + for (int i = 0; i < nn; ++i) {
1.96 + SmartUGraph::Node node = source.addNode();
1.97 + snv.push_back(node);
1.98 + snm[node] = i * i;
1.99 + if (i == 0) sn = node;
1.100 + }
1.101 +
1.102 + for (int i = 0; i < nn; ++i) {
1.103 + for (int j = 0; j < nn; ++j) {
1.104 + SmartUGraph::UEdge edge = source.addEdge(snv[i], snv[j]);
1.105 + suem[edge] = i * i + j * j;
1.106 + sem[source.direct(edge, true)] = i + j * j;
1.107 + sem[source.direct(edge, false)] = i * i + j;
1.108 + if (i == 0 && j == 0) se = source.direct(edge, true);
1.109 + if (i == 0 && j == 0) sue = edge;
1.110 + }
1.111 + }
1.112 +
1.113 + ListUGraph target;
1.114 + ListUGraph::NodeMap<int> tnm(target);
1.115 + ListUGraph::EdgeMap<int> tem(target);
1.116 + ListUGraph::UEdgeMap<int> tuem(target);
1.117 + ListUGraph::Node tn;
1.118 + ListUGraph::Edge te;
1.119 + ListUGraph::UEdge tue;
1.120 +
1.121 + SmartUGraph::NodeMap<ListUGraph::Node> nr(source);
1.122 + SmartUGraph::EdgeMap<ListUGraph::Edge> er(source);
1.123 + SmartUGraph::UEdgeMap<ListUGraph::UEdge> uer(source);
1.124 +
1.125 + ListUGraph::NodeMap<SmartUGraph::Node> ncr(target);
1.126 + ListUGraph::EdgeMap<SmartUGraph::Edge> ecr(target);
1.127 + ListUGraph::UEdgeMap<SmartUGraph::UEdge> uecr(target);
1.128 +
1.129 + UGraphCopy<ListUGraph, SmartUGraph>(target, source).
1.130 + nodeMap(tnm, snm).edgeMap(tem, sem).uEdgeMap(tuem, suem).
1.131 + nodeRef(nr).edgeRef(er).uEdgeRef(uer).
1.132 + nodeCrossRef(ncr).edgeCrossRef(ecr).uEdgeCrossRef(uecr).
1.133 + node(tn, sn).edge(te, se).uEdge(tue, sue).run();
1.134 +
1.135 + for (SmartUGraph::NodeIt it(source); it != INVALID; ++it) {
1.136 + check(ncr[nr[it]] == it, "Wrong copy.");
1.137 + check(snm[it] == tnm[nr[it]], "Wrong copy.");
1.138 + }
1.139 +
1.140 + for (SmartUGraph::EdgeIt it(source); it != INVALID; ++it) {
1.141 + check(ecr[er[it]] == it, "Wrong copy.");
1.142 + check(sem[it] == tem[er[it]], "Wrong copy.");
1.143 + check(nr[source.source(it)] ==
1.144 + target.source(er[it]), "Wrong copy.");
1.145 + check(nr[source.target(it)] ==
1.146 + target.target(er[it]), "Wrong copy.");
1.147 + }
1.148 +
1.149 + for (SmartUGraph::UEdgeIt it(source); it != INVALID; ++it) {
1.150 + check(uecr[uer[it]] == it, "Wrong copy.");
1.151 + check(suem[it] == tuem[uer[it]], "Wrong copy.");
1.152 + check(nr[source.source(it)] == target.source(uer[it]) ||
1.153 + nr[source.source(it)] == target.target(uer[it]),
1.154 + "Wrong copy.");
1.155 + check(nr[source.target(it)] == target.source(uer[it]) ||
1.156 + nr[source.target(it)] == target.target(uer[it]),
1.157 + "Wrong copy.");
1.158 + check((source.source(it) != source.target(it)) ==
1.159 + (target.source(uer[it]) != target.target(uer[it])),
1.160 + "Wrong copy.");
1.161 + }
1.162 +
1.163 + for (ListUGraph::NodeIt it(target); it != INVALID; ++it) {
1.164 + check(nr[ncr[it]] == it, "Wrong copy.");
1.165 + }
1.166 +
1.167 + for (ListUGraph::EdgeIt it(target); it != INVALID; ++it) {
1.168 + check(er[ecr[it]] == it, "Wrong copy.");
1.169 + }
1.170 + for (ListUGraph::UEdgeIt it(target); it != INVALID; ++it) {
1.171 + check(uer[uecr[it]] == it, "Wrong copy.");
1.172 + }
1.173 + check(tn == nr[sn], "Wrong copy.");
1.174 + check(te == er[se], "Wrong copy.");
1.175 + check(tue == uer[sue], "Wrong copy.");
1.176 +}
1.177 +
1.178 +void bpugraph_copy_test() {
1.179 + const int nn = 10;
1.180 +
1.181 + SmartBpUGraph source;
1.182 + SmartBpUGraph::ANodeMap<int> sanm(source);
1.183 + SmartBpUGraph::BNodeMap<int> sbnm(source);
1.184 + SmartBpUGraph::NodeMap<int> snm(source);
1.185 + SmartBpUGraph::EdgeMap<int> sem(source);
1.186 + SmartBpUGraph::UEdgeMap<int> suem(source);
1.187 + SmartBpUGraph::Node sn = INVALID;
1.188 + SmartBpUGraph::Edge se = INVALID;
1.189 + SmartBpUGraph::UEdge sue = INVALID;
1.190 +
1.191 + std::vector<SmartBpUGraph::Node> sanv;
1.192 + for (int i = 0; i < nn; ++i) {
1.193 + SmartBpUGraph::Node node = source.addANode();
1.194 + sanv.push_back(node);
1.195 + sanm[node] = i * i;
1.196 + snm[node] = i * i + i;
1.197 + if (i == 0) sn = node;
1.198 + }
1.199 +
1.200 + std::vector<SmartBpUGraph::Node> sbnv;
1.201 + for (int i = 0; i < nn; ++i) {
1.202 + SmartBpUGraph::Node node = source.addBNode();
1.203 + sbnv.push_back(node);
1.204 + sbnm[node] = i * i - i;
1.205 + snm[node] = i * i + i + 1;
1.206 + }
1.207 +
1.208 + for (int i = 0; i < nn; ++i) {
1.209 + for (int j = 0; j < nn; ++j) {
1.210 + SmartBpUGraph::UEdge edge = source.addEdge(sanv[i], sbnv[j]);
1.211 + suem[edge] = i * i + j * j;
1.212 + sem[source.direct(edge, true)] = i + j * j;
1.213 + sem[source.direct(edge, false)] = i * i + j;
1.214 + if (i == 0 && j == 0) se = source.direct(edge, true);
1.215 + if (i == 0 && j == 0) sue = edge;
1.216 + }
1.217 + }
1.218 +
1.219 + ListBpUGraph target;
1.220 + ListBpUGraph::ANodeMap<int> tanm(target);
1.221 + ListBpUGraph::BNodeMap<int> tbnm(target);
1.222 + ListBpUGraph::NodeMap<int> tnm(target);
1.223 + ListBpUGraph::EdgeMap<int> tem(target);
1.224 + ListBpUGraph::UEdgeMap<int> tuem(target);
1.225 + ListBpUGraph::Node tn;
1.226 + ListBpUGraph::Edge te;
1.227 + ListBpUGraph::UEdge tue;
1.228 +
1.229 + SmartBpUGraph::ANodeMap<ListBpUGraph::Node> anr(source);
1.230 + SmartBpUGraph::BNodeMap<ListBpUGraph::Node> bnr(source);
1.231 + SmartBpUGraph::NodeMap<ListBpUGraph::Node> nr(source);
1.232 + SmartBpUGraph::EdgeMap<ListBpUGraph::Edge> er(source);
1.233 + SmartBpUGraph::UEdgeMap<ListBpUGraph::UEdge> uer(source);
1.234 +
1.235 + ListBpUGraph::ANodeMap<SmartBpUGraph::Node> ancr(target);
1.236 + ListBpUGraph::BNodeMap<SmartBpUGraph::Node> bncr(target);
1.237 + ListBpUGraph::NodeMap<SmartBpUGraph::Node> ncr(target);
1.238 + ListBpUGraph::EdgeMap<SmartBpUGraph::Edge> ecr(target);
1.239 + ListBpUGraph::UEdgeMap<SmartBpUGraph::UEdge> uecr(target);
1.240 +
1.241 + BpUGraphCopy<ListBpUGraph, SmartBpUGraph>(target, source).
1.242 + aNodeMap(tanm, sanm).bNodeMap(tbnm, sbnm).nodeMap(tnm, snm).
1.243 + edgeMap(tem, sem).uEdgeMap(tuem, suem).
1.244 + aNodeRef(anr).bNodeRef(bnr).nodeRef(nr).edgeRef(er).uEdgeRef(uer).
1.245 + aNodeCrossRef(ancr).bNodeCrossRef(bncr).nodeCrossRef(ncr).
1.246 + edgeCrossRef(ecr).uEdgeCrossRef(uecr).
1.247 + node(tn, sn).edge(te, se).uEdge(tue, sue).run();
1.248 +
1.249 + for (SmartBpUGraph::ANodeIt it(source); it != INVALID; ++it) {
1.250 + check(nr[it] == anr[it], "Wrong copy.");
1.251 + check(ancr[anr[it]] == it, "Wrong copy.");
1.252 + check(sanm[it] == tanm[anr[it]], "Wrong copy.");
1.253 + }
1.254 +
1.255 + for (SmartBpUGraph::BNodeIt it(source); it != INVALID; ++it) {
1.256 + check(nr[it] == bnr[it], "Wrong copy.");
1.257 + check(bncr[bnr[it]] == it, "Wrong copy.");
1.258 + check(sbnm[it] == tbnm[bnr[it]], "Wrong copy.");
1.259 + }
1.260 +
1.261 + for (SmartBpUGraph::NodeIt it(source); it != INVALID; ++it) {
1.262 + check(ncr[nr[it]] == it, "Wrong copy.");
1.263 + check(snm[it] == tnm[nr[it]], "Wrong copy.");
1.264 + }
1.265 +
1.266 + for (SmartBpUGraph::EdgeIt it(source); it != INVALID; ++it) {
1.267 + check(ecr[er[it]] == it, "Wrong copy.");
1.268 + check(sem[it] == tem[er[it]], "Wrong copy.");
1.269 + check(nr[source.source(it)] ==
1.270 + target.source(er[it]), "Wrong copy.");
1.271 + check(nr[source.target(it)] ==
1.272 + target.target(er[it]), "Wrong copy.");
1.273 + }
1.274 +
1.275 + for (SmartBpUGraph::UEdgeIt it(source); it != INVALID; ++it) {
1.276 + check(uecr[uer[it]] == it, "Wrong copy.");
1.277 + check(suem[it] == tuem[uer[it]], "Wrong copy.");
1.278 + check(nr[source.aNode(it)] ==
1.279 + target.aNode(uer[it]), "Wrong copy.");
1.280 + check(nr[source.bNode(it)] ==
1.281 + target.bNode(uer[it]), "Wrong copy.");
1.282 + }
1.283 +
1.284 + for (ListBpUGraph::ANodeIt it(target); it != INVALID; ++it) {
1.285 + check(ancr[it] == ncr[it], "Wrong copy.");
1.286 + check(anr[ancr[it]] == it, "Wrong copy.");
1.287 + }
1.288 +
1.289 + for (ListBpUGraph::BNodeIt it(target); it != INVALID; ++it) {
1.290 + check(bncr[it] == ncr[it], "Wrong copy.");
1.291 + check(bnr[bncr[it]] == it, "Wrong copy.");
1.292 + }
1.293 +
1.294 + for (ListBpUGraph::NodeIt it(target); it != INVALID; ++it) {
1.295 + check(nr[ncr[it]] == it, "Wrong copy.");
1.296 + }
1.297 +
1.298 + for (ListBpUGraph::EdgeIt it(target); it != INVALID; ++it) {
1.299 + check(er[ecr[it]] == it, "Wrong copy.");
1.300 + }
1.301 + for (ListBpUGraph::UEdgeIt it(target); it != INVALID; ++it) {
1.302 + check(uer[uecr[it]] == it, "Wrong copy.");
1.303 + }
1.304 + check(tn == nr[sn], "Wrong copy.");
1.305 + check(te == er[se], "Wrong copy.");
1.306 + check(tue == uer[sue], "Wrong copy.");
1.307 +}
1.308 +
1.309 +int main() {
1.310 + graph_copy_test();
1.311 + ugraph_copy_test();
1.312 + bpugraph_copy_test();
1.313 +
1.314 + return 0;
1.315 +}