deba@937
|
1 |
/* -*- C++ -*-
|
deba@937
|
2 |
* src/test/sym_graph_test.h - Part of LEMON, a generic C++ optimization library
|
deba@937
|
3 |
*
|
deba@937
|
4 |
* Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@937
|
5 |
* (Egervary Combinatorial Optimization Research Group, EGRES).
|
deba@937
|
6 |
*
|
deba@937
|
7 |
* Permission to use, modify and distribute this software is granted
|
deba@937
|
8 |
* provided that this copyright notice appears in all copies. For
|
deba@937
|
9 |
* precise terms see the accompanying LICENSE file.
|
deba@937
|
10 |
*
|
deba@937
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@937
|
12 |
* express or implied, and with no claim as to its suitability for any
|
deba@937
|
13 |
* purpose.
|
deba@937
|
14 |
*
|
deba@937
|
15 |
*/
|
deba@937
|
16 |
#ifndef LEMON_TEST_SYM_GRAPH_TEST_H
|
deba@937
|
17 |
#define LEMON_TEST_SYM_GRAPH_TEST_H
|
deba@937
|
18 |
|
deba@937
|
19 |
|
deba@937
|
20 |
#include "graph_test.h"
|
deba@937
|
21 |
#include "test_tools.h"
|
deba@937
|
22 |
|
deba@937
|
23 |
//! \ingroup misc
|
deba@937
|
24 |
//! \file
|
deba@937
|
25 |
//! \brief Some utility to test symmetric graph classes.
|
deba@937
|
26 |
namespace lemon {
|
alpar@938
|
27 |
|
alpar@938
|
28 |
/// \e
|
deba@937
|
29 |
|
alpar@938
|
30 |
/// \todo This should go to lemon/skeleton/symgraph.h
|
alpar@938
|
31 |
///
|
deba@937
|
32 |
template<class Graph> void checkCompileStaticSymGraph(Graph &G)
|
deba@937
|
33 |
{
|
deba@937
|
34 |
typedef typename Graph::Node Node;
|
deba@937
|
35 |
typedef typename Graph::NodeIt NodeIt;
|
deba@937
|
36 |
typedef typename Graph::SymEdge SymEdge;
|
deba@937
|
37 |
typedef typename Graph::SymEdgeIt SymEdgeIt;
|
deba@937
|
38 |
typedef typename Graph::Edge Edge;
|
deba@937
|
39 |
typedef typename Graph::EdgeIt EdgeIt;
|
deba@937
|
40 |
typedef typename Graph::InEdgeIt InEdgeIt;
|
deba@937
|
41 |
typedef typename Graph::OutEdgeIt OutEdgeIt;
|
deba@937
|
42 |
|
alpar@938
|
43 |
lemon::skeleton::checkCompileStaticGraph(G);
|
deba@937
|
44 |
|
deba@937
|
45 |
{
|
deba@937
|
46 |
SymEdge i; SymEdge j(i); SymEdge k(INVALID);
|
deba@937
|
47 |
i=j;
|
deba@937
|
48 |
bool b; b=true;
|
deba@937
|
49 |
b=(i==INVALID); b=(i!=INVALID);
|
deba@937
|
50 |
b=(i==j); b=(i!=j); b=(i<j);
|
deba@937
|
51 |
Edge e;
|
deba@937
|
52 |
e = G.forward(i);
|
deba@937
|
53 |
e = G.backward(i);
|
deba@937
|
54 |
}
|
deba@937
|
55 |
{
|
deba@937
|
56 |
SymEdgeIt i; SymEdgeIt j(i); SymEdgeIt k(INVALID); SymEdgeIt l(G);
|
deba@937
|
57 |
i=j;
|
deba@937
|
58 |
j=G.first(i);
|
deba@937
|
59 |
j=++i;
|
deba@937
|
60 |
bool b; b=true;
|
deba@937
|
61 |
b=(i==INVALID); b=(i!=INVALID);
|
deba@937
|
62 |
SymEdge n(i);
|
deba@937
|
63 |
n=i;
|
deba@937
|
64 |
b=(i==j); b=(i!=j); b=(i<j);
|
deba@937
|
65 |
//SymEdge ->SymEdgeIt conversion
|
deba@937
|
66 |
SymEdgeIt ni(G,n);
|
deba@937
|
67 |
}
|
deba@937
|
68 |
{
|
deba@937
|
69 |
Edge i, j;
|
deba@937
|
70 |
j = G.opposite(i);
|
deba@937
|
71 |
}
|
deba@937
|
72 |
{
|
deba@937
|
73 |
Node n;
|
deba@937
|
74 |
SymEdge se;
|
deba@937
|
75 |
se=INVALID;
|
deba@937
|
76 |
n=G.tail(se);
|
deba@937
|
77 |
n=G.head(se);
|
deba@937
|
78 |
}
|
deba@937
|
79 |
// id tests
|
deba@937
|
80 |
{ SymEdge n; int i=G.id(n); i=i; }
|
deba@937
|
81 |
//SymEdgeMap tests
|
deba@937
|
82 |
{
|
deba@937
|
83 |
SymEdge k;
|
deba@937
|
84 |
typename Graph::template SymEdgeMap<int> m(G);
|
deba@937
|
85 |
typename Graph::template SymEdgeMap<int> const &cm = m; //Const map
|
deba@937
|
86 |
//Inicialize with default value
|
deba@937
|
87 |
typename Graph::template SymEdgeMap<int> mdef(G,12);
|
deba@937
|
88 |
typename Graph::template SymEdgeMap<int> mm(cm); //Copy
|
deba@937
|
89 |
typename Graph::template SymEdgeMap<double> dm(cm); //Copy from another type
|
deba@937
|
90 |
int v;
|
deba@937
|
91 |
v=m[k]; m[k]=v; m.set(k,v);
|
deba@937
|
92 |
v=cm[k];
|
deba@937
|
93 |
|
deba@937
|
94 |
m=cm;
|
deba@937
|
95 |
dm=cm; //Copy from another type
|
deba@937
|
96 |
{
|
deba@937
|
97 |
//Check the typedef's
|
deba@937
|
98 |
typename Graph::template SymEdgeMap<int>::ValueType val;
|
deba@937
|
99 |
val = 1;
|
deba@937
|
100 |
typename Graph::template SymEdgeMap<int>::KeyType key;
|
deba@937
|
101 |
key = typename Graph::SymEdgeIt(G);
|
deba@937
|
102 |
}
|
deba@937
|
103 |
}
|
deba@937
|
104 |
{ //bool SymEdgeMap
|
deba@937
|
105 |
SymEdge k;
|
deba@937
|
106 |
typename Graph::template SymEdgeMap<bool> m(G);
|
deba@937
|
107 |
typename Graph::template SymEdgeMap<bool> const &cm = m; //Const map
|
deba@937
|
108 |
//Inicialize with default value
|
deba@937
|
109 |
typename Graph::template SymEdgeMap<bool> mdef(G,12);
|
deba@937
|
110 |
typename Graph::template SymEdgeMap<bool> mm(cm); //Copy
|
deba@937
|
111 |
typename Graph::template SymEdgeMap<int> dm(cm); //Copy from another type
|
deba@937
|
112 |
bool v;
|
deba@937
|
113 |
v=m[k]; m[k]=v; m.set(k,v);
|
deba@937
|
114 |
v=cm[k];
|
deba@937
|
115 |
|
deba@937
|
116 |
m=cm;
|
deba@937
|
117 |
dm=cm; //Copy from another type
|
deba@937
|
118 |
m=dm; //Copy to another type
|
deba@937
|
119 |
{
|
deba@937
|
120 |
//Check the typedef's
|
deba@937
|
121 |
typename Graph::template SymEdgeMap<bool>::ValueType val;
|
deba@937
|
122 |
val=true;
|
deba@937
|
123 |
typename Graph::template SymEdgeMap<bool>::KeyType key;
|
deba@937
|
124 |
key= typename Graph::SymEdgeIt(G);
|
deba@937
|
125 |
}
|
deba@937
|
126 |
}
|
deba@937
|
127 |
}
|
deba@937
|
128 |
|
deba@937
|
129 |
template<class Graph> void checkCompileSymGraph(Graph &G)
|
deba@937
|
130 |
{
|
deba@937
|
131 |
checkCompileStaticSymGraph(G);
|
deba@937
|
132 |
|
deba@937
|
133 |
typedef typename Graph::Node Node;
|
deba@937
|
134 |
typedef typename Graph::NodeIt NodeIt;
|
deba@937
|
135 |
typedef typename Graph::SymEdge SymEdge;
|
deba@937
|
136 |
typedef typename Graph::SymEdgeIt SymEdgeIt;
|
deba@937
|
137 |
typedef typename Graph::Edge Edge;
|
deba@937
|
138 |
typedef typename Graph::EdgeIt EdgeIt;
|
deba@937
|
139 |
typedef typename Graph::InEdgeIt InEdgeIt;
|
deba@937
|
140 |
typedef typename Graph::OutEdgeIt OutEdgeIt;
|
deba@937
|
141 |
|
deba@937
|
142 |
Node n,m;
|
deba@937
|
143 |
n=G.addNode();
|
deba@937
|
144 |
m=G.addNode();
|
deba@937
|
145 |
SymEdge e;
|
deba@937
|
146 |
e = G.addEdge(n,m);
|
deba@937
|
147 |
|
deba@937
|
148 |
// G.clear();
|
deba@937
|
149 |
}
|
deba@937
|
150 |
|
deba@937
|
151 |
template<class Graph> void checkCompileSymGraphEraseSymEdge(Graph &G)
|
deba@937
|
152 |
{
|
deba@937
|
153 |
typename Graph::SymEdge n;
|
deba@937
|
154 |
G.erase(n);
|
deba@937
|
155 |
}
|
deba@937
|
156 |
|
deba@937
|
157 |
template<class Graph> void checkCompileErasableSymGraph(Graph &G)
|
deba@937
|
158 |
{
|
deba@937
|
159 |
checkCompileSymGraph(G);
|
alpar@938
|
160 |
lemon::skeleton::checkCompileGraphEraseNode(G);
|
deba@937
|
161 |
checkCompileSymGraphEraseSymEdge(G);
|
deba@937
|
162 |
}
|
deba@937
|
163 |
|
deba@937
|
164 |
template<class Graph> void checkGraphSymEdgeList(Graph &G, int nn)
|
deba@937
|
165 |
{
|
deba@937
|
166 |
typedef typename Graph::SymEdgeIt SymEdgeIt;
|
deba@937
|
167 |
|
deba@937
|
168 |
SymEdgeIt e(G);
|
deba@937
|
169 |
for(int i=0;i<nn;i++) {
|
deba@937
|
170 |
check(e!=INVALID,"Wrong SymEdge list linking.");
|
deba@937
|
171 |
++e;
|
deba@937
|
172 |
}
|
deba@937
|
173 |
check(e==INVALID,"Wrong SymEdge list linking.");
|
deba@937
|
174 |
}
|
deba@937
|
175 |
|
deba@937
|
176 |
///\file
|
deba@937
|
177 |
///\todo Check head(), tail() as well;
|
deba@937
|
178 |
|
deba@937
|
179 |
|
deba@937
|
180 |
} //namespace lemon
|
deba@937
|
181 |
|
deba@937
|
182 |
|
deba@937
|
183 |
#endif
|