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 {
|
deba@937
|
27 |
|
deba@937
|
28 |
template<class Graph> void checkCompileStaticSymGraph(Graph &G)
|
deba@937
|
29 |
{
|
deba@937
|
30 |
typedef typename Graph::Node Node;
|
deba@937
|
31 |
typedef typename Graph::NodeIt NodeIt;
|
deba@937
|
32 |
typedef typename Graph::SymEdge SymEdge;
|
deba@937
|
33 |
typedef typename Graph::SymEdgeIt SymEdgeIt;
|
deba@937
|
34 |
typedef typename Graph::Edge Edge;
|
deba@937
|
35 |
typedef typename Graph::EdgeIt EdgeIt;
|
deba@937
|
36 |
typedef typename Graph::InEdgeIt InEdgeIt;
|
deba@937
|
37 |
typedef typename Graph::OutEdgeIt OutEdgeIt;
|
deba@937
|
38 |
|
deba@937
|
39 |
checkCompileStaticGraph(G);
|
deba@937
|
40 |
|
deba@937
|
41 |
{
|
deba@937
|
42 |
SymEdge i; SymEdge j(i); SymEdge k(INVALID);
|
deba@937
|
43 |
i=j;
|
deba@937
|
44 |
bool b; b=true;
|
deba@937
|
45 |
b=(i==INVALID); b=(i!=INVALID);
|
deba@937
|
46 |
b=(i==j); b=(i!=j); b=(i<j);
|
deba@937
|
47 |
Edge e;
|
deba@937
|
48 |
e = G.forward(i);
|
deba@937
|
49 |
e = G.backward(i);
|
deba@937
|
50 |
}
|
deba@937
|
51 |
{
|
deba@937
|
52 |
SymEdgeIt i; SymEdgeIt j(i); SymEdgeIt k(INVALID); SymEdgeIt l(G);
|
deba@937
|
53 |
i=j;
|
deba@937
|
54 |
j=G.first(i);
|
deba@937
|
55 |
j=++i;
|
deba@937
|
56 |
bool b; b=true;
|
deba@937
|
57 |
b=(i==INVALID); b=(i!=INVALID);
|
deba@937
|
58 |
SymEdge n(i);
|
deba@937
|
59 |
n=i;
|
deba@937
|
60 |
b=(i==j); b=(i!=j); b=(i<j);
|
deba@937
|
61 |
//SymEdge ->SymEdgeIt conversion
|
deba@937
|
62 |
SymEdgeIt ni(G,n);
|
deba@937
|
63 |
}
|
deba@937
|
64 |
{
|
deba@937
|
65 |
Edge i, j;
|
deba@937
|
66 |
j = G.opposite(i);
|
deba@937
|
67 |
}
|
deba@937
|
68 |
{
|
deba@937
|
69 |
Node n;
|
deba@937
|
70 |
SymEdge se;
|
deba@937
|
71 |
se=INVALID;
|
deba@937
|
72 |
n=G.tail(se);
|
deba@937
|
73 |
n=G.head(se);
|
deba@937
|
74 |
}
|
deba@937
|
75 |
// id tests
|
deba@937
|
76 |
{ SymEdge n; int i=G.id(n); i=i; }
|
deba@937
|
77 |
//SymEdgeMap tests
|
deba@937
|
78 |
{
|
deba@937
|
79 |
SymEdge k;
|
deba@937
|
80 |
typename Graph::template SymEdgeMap<int> m(G);
|
deba@937
|
81 |
typename Graph::template SymEdgeMap<int> const &cm = m; //Const map
|
deba@937
|
82 |
//Inicialize with default value
|
deba@937
|
83 |
typename Graph::template SymEdgeMap<int> mdef(G,12);
|
deba@937
|
84 |
typename Graph::template SymEdgeMap<int> mm(cm); //Copy
|
deba@937
|
85 |
typename Graph::template SymEdgeMap<double> dm(cm); //Copy from another type
|
deba@937
|
86 |
int v;
|
deba@937
|
87 |
v=m[k]; m[k]=v; m.set(k,v);
|
deba@937
|
88 |
v=cm[k];
|
deba@937
|
89 |
|
deba@937
|
90 |
m=cm;
|
deba@937
|
91 |
dm=cm; //Copy from another type
|
deba@937
|
92 |
{
|
deba@937
|
93 |
//Check the typedef's
|
deba@937
|
94 |
typename Graph::template SymEdgeMap<int>::ValueType val;
|
deba@937
|
95 |
val = 1;
|
deba@937
|
96 |
typename Graph::template SymEdgeMap<int>::KeyType key;
|
deba@937
|
97 |
key = typename Graph::SymEdgeIt(G);
|
deba@937
|
98 |
}
|
deba@937
|
99 |
}
|
deba@937
|
100 |
{ //bool SymEdgeMap
|
deba@937
|
101 |
SymEdge k;
|
deba@937
|
102 |
typename Graph::template SymEdgeMap<bool> m(G);
|
deba@937
|
103 |
typename Graph::template SymEdgeMap<bool> const &cm = m; //Const map
|
deba@937
|
104 |
//Inicialize with default value
|
deba@937
|
105 |
typename Graph::template SymEdgeMap<bool> mdef(G,12);
|
deba@937
|
106 |
typename Graph::template SymEdgeMap<bool> mm(cm); //Copy
|
deba@937
|
107 |
typename Graph::template SymEdgeMap<int> dm(cm); //Copy from another type
|
deba@937
|
108 |
bool v;
|
deba@937
|
109 |
v=m[k]; m[k]=v; m.set(k,v);
|
deba@937
|
110 |
v=cm[k];
|
deba@937
|
111 |
|
deba@937
|
112 |
m=cm;
|
deba@937
|
113 |
dm=cm; //Copy from another type
|
deba@937
|
114 |
m=dm; //Copy to another type
|
deba@937
|
115 |
{
|
deba@937
|
116 |
//Check the typedef's
|
deba@937
|
117 |
typename Graph::template SymEdgeMap<bool>::ValueType val;
|
deba@937
|
118 |
val=true;
|
deba@937
|
119 |
typename Graph::template SymEdgeMap<bool>::KeyType key;
|
deba@937
|
120 |
key= typename Graph::SymEdgeIt(G);
|
deba@937
|
121 |
}
|
deba@937
|
122 |
}
|
deba@937
|
123 |
}
|
deba@937
|
124 |
|
deba@937
|
125 |
template<class Graph> void checkCompileSymGraph(Graph &G)
|
deba@937
|
126 |
{
|
deba@937
|
127 |
checkCompileStaticSymGraph(G);
|
deba@937
|
128 |
|
deba@937
|
129 |
typedef typename Graph::Node Node;
|
deba@937
|
130 |
typedef typename Graph::NodeIt NodeIt;
|
deba@937
|
131 |
typedef typename Graph::SymEdge SymEdge;
|
deba@937
|
132 |
typedef typename Graph::SymEdgeIt SymEdgeIt;
|
deba@937
|
133 |
typedef typename Graph::Edge Edge;
|
deba@937
|
134 |
typedef typename Graph::EdgeIt EdgeIt;
|
deba@937
|
135 |
typedef typename Graph::InEdgeIt InEdgeIt;
|
deba@937
|
136 |
typedef typename Graph::OutEdgeIt OutEdgeIt;
|
deba@937
|
137 |
|
deba@937
|
138 |
Node n,m;
|
deba@937
|
139 |
n=G.addNode();
|
deba@937
|
140 |
m=G.addNode();
|
deba@937
|
141 |
SymEdge e;
|
deba@937
|
142 |
e = G.addEdge(n,m);
|
deba@937
|
143 |
|
deba@937
|
144 |
// G.clear();
|
deba@937
|
145 |
}
|
deba@937
|
146 |
|
deba@937
|
147 |
template<class Graph> void checkCompileSymGraphEraseSymEdge(Graph &G)
|
deba@937
|
148 |
{
|
deba@937
|
149 |
typename Graph::SymEdge n;
|
deba@937
|
150 |
G.erase(n);
|
deba@937
|
151 |
}
|
deba@937
|
152 |
|
deba@937
|
153 |
template<class Graph> void checkCompileErasableSymGraph(Graph &G)
|
deba@937
|
154 |
{
|
deba@937
|
155 |
checkCompileSymGraph(G);
|
deba@937
|
156 |
checkCompileGraphEraseNode(G);
|
deba@937
|
157 |
checkCompileSymGraphEraseSymEdge(G);
|
deba@937
|
158 |
}
|
deba@937
|
159 |
|
deba@937
|
160 |
template<class Graph> void checkGraphSymEdgeList(Graph &G, int nn)
|
deba@937
|
161 |
{
|
deba@937
|
162 |
typedef typename Graph::SymEdgeIt SymEdgeIt;
|
deba@937
|
163 |
|
deba@937
|
164 |
SymEdgeIt e(G);
|
deba@937
|
165 |
for(int i=0;i<nn;i++) {
|
deba@937
|
166 |
check(e!=INVALID,"Wrong SymEdge list linking.");
|
deba@937
|
167 |
++e;
|
deba@937
|
168 |
}
|
deba@937
|
169 |
check(e==INVALID,"Wrong SymEdge list linking.");
|
deba@937
|
170 |
}
|
deba@937
|
171 |
|
deba@937
|
172 |
///\file
|
deba@937
|
173 |
///\todo Check head(), tail() as well;
|
deba@937
|
174 |
|
deba@937
|
175 |
|
deba@937
|
176 |
} //namespace lemon
|
deba@937
|
177 |
|
deba@937
|
178 |
|
deba@937
|
179 |
#endif
|