1.1 --- a/test/CMakeLists.txt Thu Jul 10 16:03:23 2008 +0200
1.2 +++ b/test/CMakeLists.txt Thu Jul 10 16:05:56 2008 +0200
1.3 @@ -10,6 +10,7 @@
1.4 dijkstra_test
1.5 dim_test
1.6 error_test
1.7 + graph_copy_test
1.8 graph_test
1.9 graph_utils_test
1.10 kruskal_test
2.1 --- a/test/Makefile.am Thu Jul 10 16:03:23 2008 +0200
2.2 +++ b/test/Makefile.am Thu Jul 10 16:05:56 2008 +0200
2.3 @@ -15,6 +15,7 @@
2.4 test/dijkstra_test \
2.5 test/dim_test \
2.6 test/error_test \
2.7 + test/graph_copy_test \
2.8 test/graph_test \
2.9 test/graph_utils_test \
2.10 test/kruskal_test \
2.11 @@ -36,6 +37,7 @@
2.12 test_dijkstra_test_SOURCES = test/dijkstra_test.cc
2.13 test_dim_test_SOURCES = test/dim_test.cc
2.14 test_error_test_SOURCES = test/error_test.cc
2.15 +test_graph_copy_test_SOURCES = test/graph_copy_test.cc
2.16 test_graph_test_SOURCES = test/graph_test.cc
2.17 test_graph_utils_test_SOURCES = test/graph_utils_test.cc
2.18 # test_heap_test_SOURCES = test/heap_test.cc
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/test/graph_copy_test.cc Thu Jul 10 16:05:56 2008 +0200
3.3 @@ -0,0 +1,192 @@
3.4 +/* -*- C++ -*-
3.5 + *
3.6 + * This file is a part of LEMON, a generic C++ optimization library
3.7 + *
3.8 + * Copyright (C) 2003-2008
3.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
3.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
3.11 + *
3.12 + * Permission to use, modify and distribute this software is granted
3.13 + * provided that this copyright notice appears in all copies. For
3.14 + * precise terms see the accompanying LICENSE file.
3.15 + *
3.16 + * This software is provided "AS IS" with no warranty of any kind,
3.17 + * express or implied, and with no claim as to its suitability for any
3.18 + * purpose.
3.19 + *
3.20 + */
3.21 +
3.22 +#include <lemon/smart_graph.h>
3.23 +#include <lemon/list_graph.h>
3.24 +#include <lemon/lgf_reader.h>
3.25 +#include <lemon/graph_utils.h>
3.26 +#include <lemon/error.h>
3.27 +
3.28 +#include "test_tools.h"
3.29 +
3.30 +using namespace std;
3.31 +using namespace lemon;
3.32 +
3.33 +void digraph_copy_test() {
3.34 + const int nn = 10;
3.35 +
3.36 + SmartDigraph from;
3.37 + SmartDigraph::NodeMap<int> fnm(from);
3.38 + SmartDigraph::ArcMap<int> fam(from);
3.39 + SmartDigraph::Node fn = INVALID;
3.40 + SmartDigraph::Arc fa = INVALID;
3.41 +
3.42 + std::vector<SmartDigraph::Node> fnv;
3.43 + for (int i = 0; i < nn; ++i) {
3.44 + SmartDigraph::Node node = from.addNode();
3.45 + fnv.push_back(node);
3.46 + fnm[node] = i * i;
3.47 + if (i == 0) fn = node;
3.48 + }
3.49 +
3.50 + for (int i = 0; i < nn; ++i) {
3.51 + for (int j = 0; j < nn; ++j) {
3.52 + SmartDigraph::Arc arc = from.addArc(fnv[i], fnv[j]);
3.53 + fam[arc] = i + j * j;
3.54 + if (i == 0 && j == 0) fa = arc;
3.55 + }
3.56 + }
3.57 +
3.58 + ListDigraph to;
3.59 + ListDigraph::NodeMap<int> tnm(to);
3.60 + ListDigraph::ArcMap<int> tam(to);
3.61 + ListDigraph::Node tn;
3.62 + ListDigraph::Arc ta;
3.63 +
3.64 + SmartDigraph::NodeMap<ListDigraph::Node> nr(from);
3.65 + SmartDigraph::ArcMap<ListDigraph::Arc> er(from);
3.66 +
3.67 + ListDigraph::NodeMap<SmartDigraph::Node> ncr(to);
3.68 + ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to);
3.69 +
3.70 + DigraphCopy<ListDigraph, SmartDigraph>(to, from).
3.71 + nodeMap(tnm, fnm).arcMap(tam, fam).
3.72 + nodeRef(nr).arcRef(er).
3.73 + nodeCrossRef(ncr).arcCrossRef(ecr).
3.74 + node(tn, fn).arc(ta, fa).run();
3.75 +
3.76 + for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) {
3.77 + check(ncr[nr[it]] == it, "Wrong copy.");
3.78 + check(fnm[it] == tnm[nr[it]], "Wrong copy.");
3.79 + }
3.80 +
3.81 + for (SmartDigraph::ArcIt it(from); it != INVALID; ++it) {
3.82 + check(ecr[er[it]] == it, "Wrong copy.");
3.83 + check(fam[it] == tam[er[it]], "Wrong copy.");
3.84 + check(nr[from.source(it)] == to.source(er[it]), "Wrong copy.");
3.85 + check(nr[from.target(it)] == to.target(er[it]), "Wrong copy.");
3.86 + }
3.87 +
3.88 + for (ListDigraph::NodeIt it(to); it != INVALID; ++it) {
3.89 + check(nr[ncr[it]] == it, "Wrong copy.");
3.90 + }
3.91 +
3.92 + for (ListDigraph::ArcIt it(to); it != INVALID; ++it) {
3.93 + check(er[ecr[it]] == it, "Wrong copy.");
3.94 + }
3.95 + check(tn == nr[fn], "Wrong copy.");
3.96 + check(ta == er[fa], "Wrong copy.");
3.97 +}
3.98 +
3.99 +void graph_copy_test() {
3.100 + const int nn = 10;
3.101 +
3.102 + SmartGraph from;
3.103 + SmartGraph::NodeMap<int> fnm(from);
3.104 + SmartGraph::ArcMap<int> fam(from);
3.105 + SmartGraph::EdgeMap<int> fem(from);
3.106 + SmartGraph::Node fn = INVALID;
3.107 + SmartGraph::Arc fa = INVALID;
3.108 + SmartGraph::Edge fe = INVALID;
3.109 +
3.110 + std::vector<SmartGraph::Node> fnv;
3.111 + for (int i = 0; i < nn; ++i) {
3.112 + SmartGraph::Node node = from.addNode();
3.113 + fnv.push_back(node);
3.114 + fnm[node] = i * i;
3.115 + if (i == 0) fn = node;
3.116 + }
3.117 +
3.118 + for (int i = 0; i < nn; ++i) {
3.119 + for (int j = 0; j < nn; ++j) {
3.120 + SmartGraph::Edge edge = from.addEdge(fnv[i], fnv[j]);
3.121 + fem[edge] = i * i + j * j;
3.122 + fam[from.direct(edge, true)] = i + j * j;
3.123 + fam[from.direct(edge, false)] = i * i + j;
3.124 + if (i == 0 && j == 0) fa = from.direct(edge, true);
3.125 + if (i == 0 && j == 0) fe = edge;
3.126 + }
3.127 + }
3.128 +
3.129 + ListGraph to;
3.130 + ListGraph::NodeMap<int> tnm(to);
3.131 + ListGraph::ArcMap<int> tam(to);
3.132 + ListGraph::EdgeMap<int> tem(to);
3.133 + ListGraph::Node tn;
3.134 + ListGraph::Arc ta;
3.135 + ListGraph::Edge te;
3.136 +
3.137 + SmartGraph::NodeMap<ListGraph::Node> nr(from);
3.138 + SmartGraph::ArcMap<ListGraph::Arc> ar(from);
3.139 + SmartGraph::EdgeMap<ListGraph::Edge> er(from);
3.140 +
3.141 + ListGraph::NodeMap<SmartGraph::Node> ncr(to);
3.142 + ListGraph::ArcMap<SmartGraph::Arc> acr(to);
3.143 + ListGraph::EdgeMap<SmartGraph::Edge> ecr(to);
3.144 +
3.145 + GraphCopy<ListGraph, SmartGraph>(to, from).
3.146 + nodeMap(tnm, fnm).arcMap(tam, fam).edgeMap(tem, fem).
3.147 + nodeRef(nr).arcRef(ar).edgeRef(er).
3.148 + nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr).
3.149 + node(tn, fn).arc(ta, fa).edge(te, fe).run();
3.150 +
3.151 + for (SmartGraph::NodeIt it(from); it != INVALID; ++it) {
3.152 + check(ncr[nr[it]] == it, "Wrong copy.");
3.153 + check(fnm[it] == tnm[nr[it]], "Wrong copy.");
3.154 + }
3.155 +
3.156 + for (SmartGraph::ArcIt it(from); it != INVALID; ++it) {
3.157 + check(acr[ar[it]] == it, "Wrong copy.");
3.158 + check(fam[it] == tam[ar[it]], "Wrong copy.");
3.159 + check(nr[from.source(it)] == to.source(ar[it]), "Wrong copy.");
3.160 + check(nr[from.target(it)] == to.target(ar[it]), "Wrong copy.");
3.161 + }
3.162 +
3.163 + for (SmartGraph::EdgeIt it(from); it != INVALID; ++it) {
3.164 + check(ecr[er[it]] == it, "Wrong copy.");
3.165 + check(fem[it] == tem[er[it]], "Wrong copy.");
3.166 + check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]),
3.167 + "Wrong copy.");
3.168 + check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]),
3.169 + "Wrong copy.");
3.170 + check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])),
3.171 + "Wrong copy.");
3.172 + }
3.173 +
3.174 + for (ListGraph::NodeIt it(to); it != INVALID; ++it) {
3.175 + check(nr[ncr[it]] == it, "Wrong copy.");
3.176 + }
3.177 +
3.178 + for (ListGraph::ArcIt it(to); it != INVALID; ++it) {
3.179 + check(ar[acr[it]] == it, "Wrong copy.");
3.180 + }
3.181 + for (ListGraph::EdgeIt it(to); it != INVALID; ++it) {
3.182 + check(er[ecr[it]] == it, "Wrong copy.");
3.183 + }
3.184 + check(tn == nr[fn], "Wrong copy.");
3.185 + check(ta == ar[fa], "Wrong copy.");
3.186 + check(te == er[fe], "Wrong copy.");
3.187 +}
3.188 +
3.189 +
3.190 +int main() {
3.191 + digraph_copy_test();
3.192 + graph_copy_test();
3.193 +
3.194 + return 0;
3.195 +}