1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2009
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_TEST_GRAPH_TEST_H
20 #define LEMON_TEST_GRAPH_TEST_H
24 #include <lemon/core.h>
25 #include <lemon/maps.h>
27 #include "test_tools.h"
32 void checkGraphNodeList(const Graph &G, int cnt)
34 typename Graph::NodeIt n(G);
35 for(int i=0;i<cnt;i++) {
36 check(n!=INVALID,"Wrong Node list linking.");
39 check(n==INVALID,"Wrong Node list linking.");
40 check(countNodes(G)==cnt,"Wrong Node number.");
44 void checkGraphRedNodeList(const Graph &G, int cnt)
46 typename Graph::RedNodeIt n(G);
47 for(int i=0;i<cnt;i++) {
48 check(n!=INVALID,"Wrong red Node list linking.");
49 check(G.red(n),"Wrong node set check.");
50 check(!G.blue(n),"Wrong node set check.");
51 typename Graph::Node nn = n;
52 check(G.asRedNodeUnsafe(nn) == n,"Wrong node conversion.");
53 check(G.asRedNode(nn) == n,"Wrong node conversion.");
54 check(G.asBlueNode(nn) == INVALID,"Wrong node conversion.");
55 std::pair<typename Graph::RedNode, typename Graph::BlueNode> rbn =
57 check(rbn.first == n,"Wrong node conversion.");
58 check(rbn.second == INVALID,"Wrong node conversion.");
61 check(n==INVALID,"Wrong red Node list linking.");
62 check(countRedNodes(G)==cnt,"Wrong red Node number.");
66 void checkGraphBlueNodeList(const Graph &G, int cnt)
68 typename Graph::BlueNodeIt n(G);
69 for(int i=0;i<cnt;i++) {
70 check(n!=INVALID,"Wrong blue Node list linking.");
71 check(G.blue(n),"Wrong node set check.");
72 check(!G.red(n),"Wrong node set check.");
73 typename Graph::Node nn = n;
74 check(G.asBlueNodeUnsafe(nn) == n,"Wrong node conversion.");
75 check(G.asBlueNode(nn) == n,"Wrong node conversion.");
76 check(G.asRedNode(nn) == INVALID,"Wrong node conversion.");
77 std::pair<typename Graph::RedNode, typename Graph::BlueNode> rbn =
79 check(rbn.first == INVALID,"Wrong node conversion.");
80 check(rbn.second == n,"Wrong node conversion.");
83 check(n==INVALID,"Wrong blue Node list linking.");
84 check(countBlueNodes(G)==cnt,"Wrong blue Node number.");
88 void checkGraphArcList(const Graph &G, int cnt)
90 typename Graph::ArcIt e(G);
91 for(int i=0;i<cnt;i++) {
92 check(e!=INVALID,"Wrong Arc list linking.");
93 check(G.oppositeNode(G.source(e), e) == G.target(e),
94 "Wrong opposite node");
95 check(G.oppositeNode(G.target(e), e) == G.source(e),
96 "Wrong opposite node");
99 check(e==INVALID,"Wrong Arc list linking.");
100 check(countArcs(G)==cnt,"Wrong Arc number.");
103 template<class Graph>
104 void checkGraphOutArcList(const Graph &G, typename Graph::Node n, int cnt)
106 typename Graph::OutArcIt e(G,n);
107 for(int i=0;i<cnt;i++) {
108 check(e!=INVALID,"Wrong OutArc list linking.");
109 check(n==G.source(e),"Wrong OutArc list linking.");
110 check(n==G.baseNode(e),"Wrong OutArc list linking.");
111 check(G.target(e)==G.runningNode(e),"Wrong OutArc list linking.");
114 check(e==INVALID,"Wrong OutArc list linking.");
115 check(countOutArcs(G,n)==cnt,"Wrong OutArc number.");
118 template<class Graph>
119 void checkGraphInArcList(const Graph &G, typename Graph::Node n, int cnt)
121 typename Graph::InArcIt e(G,n);
122 for(int i=0;i<cnt;i++) {
123 check(e!=INVALID,"Wrong InArc list linking.");
124 check(n==G.target(e),"Wrong InArc list linking.");
125 check(n==G.baseNode(e),"Wrong OutArc list linking.");
126 check(G.source(e)==G.runningNode(e),"Wrong OutArc list linking.");
129 check(e==INVALID,"Wrong InArc list linking.");
130 check(countInArcs(G,n)==cnt,"Wrong InArc number.");
133 template<class Graph>
134 void checkGraphEdgeList(const Graph &G, int cnt)
136 typename Graph::EdgeIt e(G);
137 for(int i=0;i<cnt;i++) {
138 check(e!=INVALID,"Wrong Edge list linking.");
139 check(G.oppositeNode(G.u(e), e) == G.v(e), "Wrong opposite node");
140 check(G.oppositeNode(G.v(e), e) == G.u(e), "Wrong opposite node");
143 check(e==INVALID,"Wrong Edge list linking.");
144 check(countEdges(G)==cnt,"Wrong Edge number.");
147 template<class Graph>
148 void checkGraphIncEdgeList(const Graph &G, typename Graph::Node n, int cnt)
150 typename Graph::IncEdgeIt e(G,n);
151 for(int i=0;i<cnt;i++) {
152 check(e!=INVALID,"Wrong IncEdge list linking.");
153 check(n==G.u(e) || n==G.v(e),"Wrong IncEdge list linking.");
154 check(n==G.baseNode(e),"Wrong OutArc list linking.");
155 check(G.u(e)==G.runningNode(e) || G.v(e)==G.runningNode(e),
156 "Wrong OutArc list linking.");
159 check(e==INVALID,"Wrong IncEdge list linking.");
160 check(countIncEdges(G,n)==cnt,"Wrong IncEdge number.");
163 template <class Graph>
164 void checkGraphIncEdgeArcLists(const Graph &G, typename Graph::Node n,
167 checkGraphIncEdgeList(G, n, cnt);
168 checkGraphOutArcList(G, n, cnt);
169 checkGraphInArcList(G, n, cnt);
172 template <class Graph>
173 void checkGraphConArcList(const Graph &G, int cnt) {
175 for (typename Graph::NodeIt u(G); u != INVALID; ++u) {
176 for (typename Graph::NodeIt v(G); v != INVALID; ++v) {
177 for (ConArcIt<Graph> a(G, u, v); a != INVALID; ++a) {
178 check(G.source(a) == u, "Wrong iterator.");
179 check(G.target(a) == v, "Wrong iterator.");
184 check(cnt == i, "Wrong iterator.");
187 template <class Graph>
188 void checkGraphConEdgeList(const Graph &G, int cnt) {
190 for (typename Graph::NodeIt u(G); u != INVALID; ++u) {
191 for (typename Graph::NodeIt v(G); v != INVALID; ++v) {
192 for (ConEdgeIt<Graph> e(G, u, v); e != INVALID; ++e) {
193 check((G.u(e) == u && G.v(e) == v) ||
194 (G.u(e) == v && G.v(e) == u), "Wrong iterator.");
199 check(2 * cnt == i, "Wrong iterator.");
202 template <typename Graph>
203 void checkArcDirections(const Graph& G) {
204 for (typename Graph::ArcIt a(G); a != INVALID; ++a) {
205 check(G.source(a) == G.target(G.oppositeArc(a)), "Wrong direction");
206 check(G.target(a) == G.source(G.oppositeArc(a)), "Wrong direction");
207 check(G.direct(a, G.direction(a)) == a, "Wrong direction");
211 template <typename Graph>
212 void checkNodeIds(const Graph& G) {
213 typedef typename Graph::Node Node;
214 std::set<int> values;
215 for (typename Graph::NodeIt n(G); n != INVALID; ++n) {
216 check(G.nodeFromId(G.id(n)) == n, "Wrong id");
217 check(values.find(G.id(n)) == values.end(), "Wrong id");
218 check(G.id(n) <= G.maxNodeId(), "Wrong maximum id");
219 values.insert(G.id(n));
221 check(G.maxId(Node()) <= G.maxNodeId(), "Wrong maximum id");
224 template <typename Graph>
225 void checkRedNodeIds(const Graph& G) {
226 typedef typename Graph::RedNode RedNode;
227 std::set<int> values;
228 for (typename Graph::RedNodeIt n(G); n != INVALID; ++n) {
229 check(G.red(n), "Wrong partition");
230 check(values.find(G.id(n)) == values.end(), "Wrong id");
231 check(G.id(n) <= G.maxRedId(), "Wrong maximum id");
232 values.insert(G.id(n));
234 check(G.maxId(RedNode()) == G.maxRedId(), "Wrong maximum id");
237 template <typename Graph>
238 void checkBlueNodeIds(const Graph& G) {
239 typedef typename Graph::BlueNode BlueNode;
240 std::set<int> values;
241 for (typename Graph::BlueNodeIt n(G); n != INVALID; ++n) {
242 check(G.blue(n), "Wrong partition");
243 check(values.find(G.id(n)) == values.end(), "Wrong id");
244 check(G.id(n) <= G.maxBlueId(), "Wrong maximum id");
245 values.insert(G.id(n));
247 check(G.maxId(BlueNode()) == G.maxBlueId(), "Wrong maximum id");
250 template <typename Graph>
251 void checkArcIds(const Graph& G) {
252 typedef typename Graph::Arc Arc;
253 std::set<int> values;
254 for (typename Graph::ArcIt a(G); a != INVALID; ++a) {
255 check(G.arcFromId(G.id(a)) == a, "Wrong id");
256 check(values.find(G.id(a)) == values.end(), "Wrong id");
257 check(G.id(a) <= G.maxArcId(), "Wrong maximum id");
258 values.insert(G.id(a));
260 check(G.maxId(Arc()) <= G.maxArcId(), "Wrong maximum id");
263 template <typename Graph>
264 void checkEdgeIds(const Graph& G) {
265 typedef typename Graph::Edge Edge;
266 std::set<int> values;
267 for (typename Graph::EdgeIt e(G); e != INVALID; ++e) {
268 check(G.edgeFromId(G.id(e)) == e, "Wrong id");
269 check(values.find(G.id(e)) == values.end(), "Wrong id");
270 check(G.id(e) <= G.maxEdgeId(), "Wrong maximum id");
271 values.insert(G.id(e));
273 check(G.maxId(Edge()) <= G.maxEdgeId(), "Wrong maximum id");
276 template <typename Graph>
277 void checkGraphNodeMap(const Graph& G) {
278 typedef typename Graph::Node Node;
279 typedef typename Graph::NodeIt NodeIt;
281 typedef typename Graph::template NodeMap<int> IntNodeMap;
282 IntNodeMap map(G, 42);
283 for (NodeIt it(G); it != INVALID; ++it) {
284 check(map[it] == 42, "Wrong map constructor.");
287 for (NodeIt it(G); it != INVALID; ++it) {
289 check(map[it] == 0, "Wrong operator[].");
291 check(map[it] == s, "Wrong set.");
295 for (NodeIt it(G); it != INVALID; ++it) {
298 check(s == 0, "Wrong sum.");
300 // map = constMap<Node>(12);
301 // for (NodeIt it(G); it != INVALID; ++it) {
302 // check(map[it] == 12, "Wrong operator[].");
306 template <typename Graph>
307 void checkGraphRedNodeMap(const Graph& G) {
308 typedef typename Graph::Node Node;
309 typedef typename Graph::RedNodeIt RedNodeIt;
311 typedef typename Graph::template RedNodeMap<int> IntRedNodeMap;
312 IntRedNodeMap map(G, 42);
313 for (RedNodeIt it(G); it != INVALID; ++it) {
314 check(map[it] == 42, "Wrong map constructor.");
317 for (RedNodeIt it(G); it != INVALID; ++it) {
319 check(map[it] == 0, "Wrong operator[].");
321 check(map[it] == s, "Wrong set.");
325 for (RedNodeIt it(G); it != INVALID; ++it) {
328 check(s == 0, "Wrong sum.");
330 // map = constMap<Node>(12);
331 // for (NodeIt it(G); it != INVALID; ++it) {
332 // check(map[it] == 12, "Wrong operator[].");
336 template <typename Graph>
337 void checkGraphBlueNodeMap(const Graph& G) {
338 typedef typename Graph::Node Node;
339 typedef typename Graph::BlueNodeIt BlueNodeIt;
341 typedef typename Graph::template BlueNodeMap<int> IntBlueNodeMap;
342 IntBlueNodeMap map(G, 42);
343 for (BlueNodeIt it(G); it != INVALID; ++it) {
344 check(map[it] == 42, "Wrong map constructor.");
347 for (BlueNodeIt it(G); it != INVALID; ++it) {
349 check(map[it] == 0, "Wrong operator[].");
351 check(map[it] == s, "Wrong set.");
355 for (BlueNodeIt it(G); it != INVALID; ++it) {
358 check(s == 0, "Wrong sum.");
360 // map = constMap<Node>(12);
361 // for (NodeIt it(G); it != INVALID; ++it) {
362 // check(map[it] == 12, "Wrong operator[].");
366 template <typename Graph>
367 void checkGraphArcMap(const Graph& G) {
368 typedef typename Graph::Arc Arc;
369 typedef typename Graph::ArcIt ArcIt;
371 typedef typename Graph::template ArcMap<int> IntArcMap;
372 IntArcMap map(G, 42);
373 for (ArcIt it(G); it != INVALID; ++it) {
374 check(map[it] == 42, "Wrong map constructor.");
377 for (ArcIt it(G); it != INVALID; ++it) {
379 check(map[it] == 0, "Wrong operator[].");
381 check(map[it] == s, "Wrong set.");
385 for (ArcIt it(G); it != INVALID; ++it) {
388 check(s == 0, "Wrong sum.");
390 // map = constMap<Arc>(12);
391 // for (ArcIt it(G); it != INVALID; ++it) {
392 // check(map[it] == 12, "Wrong operator[].");
396 template <typename Graph>
397 void checkGraphEdgeMap(const Graph& G) {
398 typedef typename Graph::Edge Edge;
399 typedef typename Graph::EdgeIt EdgeIt;
401 typedef typename Graph::template EdgeMap<int> IntEdgeMap;
402 IntEdgeMap map(G, 42);
403 for (EdgeIt it(G); it != INVALID; ++it) {
404 check(map[it] == 42, "Wrong map constructor.");
407 for (EdgeIt it(G); it != INVALID; ++it) {
409 check(map[it] == 0, "Wrong operator[].");
411 check(map[it] == s, "Wrong set.");
415 for (EdgeIt it(G); it != INVALID; ++it) {
418 check(s == 0, "Wrong sum.");
420 // map = constMap<Edge>(12);
421 // for (EdgeIt it(G); it != INVALID; ++it) {
422 // check(map[it] == 12, "Wrong operator[].");