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