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
22 #include <lemon/concept_check.h>
23 #include <lemon/concepts/maps.h>
24 #include <lemon/maps.h>
25 #include <lemon/list_graph.h>
26 #include <lemon/smart_graph.h>
27 #include <lemon/adaptors.h>
28 #include <lemon/dfs.h>
30 #include "test_tools.h"
32 using namespace lemon;
33 using namespace lemon::concepts;
36 inline bool operator<(A, A) { return true; }
47 typedef A argument_type;
48 typedef B result_type;
50 B operator()(const A&) const { return B(); }
52 F& operator=(const F&);
55 int func(A) { return 3; }
57 int binc(int a, B) { return a+1; }
59 typedef ReadMap<A, double> DoubleMap;
60 typedef ReadWriteMap<A, double> DoubleWriteMap;
61 typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
63 typedef ReadMap<A, bool> BoolMap;
64 typedef ReadWriteMap<A, bool> BoolWriteMap;
65 typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
67 template<typename Map1, typename Map2, typename ItemIt>
68 void compareMap(const Map1& map1, const Map2& map2, ItemIt it) {
69 for (; it != INVALID; ++it)
70 check(map1[it] == map2[it], "The maps are not equal");
76 checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
77 checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
78 checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
79 checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
80 checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
81 checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
82 checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
83 checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
87 checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
89 NullMap<A,B> map2 = map1;
90 map1 = nullMap<A,B>();
95 checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
96 checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
98 ConstMap<A,B> map2 = B();
99 ConstMap<A,B> map3 = map1;
100 map1 = constMap<A>(B());
101 map1 = constMap<A,B>();
103 ConstMap<A,C> map4(C(1));
104 ConstMap<A,C> map5 = map4;
105 map4 = constMap<A>(C(2));
108 checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
109 check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
111 checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
112 ConstMap<A,Const<int,10> > map6;
113 ConstMap<A,Const<int,10> > map7 = map6;
114 map6 = constMap<A,int,10>();
115 map7 = constMap<A,Const<int,10> >();
116 check(map6[A()] == 10 && map7[A()] == 10,
117 "Something is wrong with ConstMap");
122 checkConcept<ReadMap<A,A>, IdentityMap<A> >();
124 IdentityMap<A> map2 = map1;
125 map1 = identityMap<A>();
127 checkConcept<ReadMap<double,double>, IdentityMap<double> >();
128 check(identityMap<double>()[1.0] == 1.0 &&
129 identityMap<double>()[3.14] == 3.14,
130 "Something is wrong with IdentityMap");
135 checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >();
137 RangeMap<B> map2(10);
138 RangeMap<B> map3(10,B());
139 RangeMap<B> map4 = map1;
140 RangeMap<B> map5 = rangeMap<B>();
141 RangeMap<B> map6 = rangeMap<B>(10);
142 RangeMap<B> map7 = rangeMap(10,B());
144 checkConcept< ReferenceMap<int, double, double&, const double&>,
145 RangeMap<double> >();
146 std::vector<double> v(10, 0);
148 RangeMap<double> map8(v);
149 RangeMap<double> map9 = rangeMap(v);
150 check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100,
151 "Something is wrong with RangeMap");
156 checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >();
158 SparseMap<A,B> map2 = B();
159 SparseMap<A,B> map3 = sparseMap<A,B>();
160 SparseMap<A,B> map4 = sparseMap<A>(B());
162 checkConcept< ReferenceMap<double, int, int&, const int&>,
163 SparseMap<double, int> >();
164 std::map<double, int> m;
165 SparseMap<double, int> map5(m);
166 SparseMap<double, int> map6(m,10);
167 SparseMap<double, int> map7 = sparseMap(m);
168 SparseMap<double, int> map8 = sparseMap(m,10);
170 check(map5[1.0] == 0 && map5[3.14] == 0 &&
171 map6[1.0] == 10 && map6[3.14] == 10,
172 "Something is wrong with SparseMap");
173 map5[1.0] = map6[3.14] = 100;
174 check(map5[1.0] == 100 && map5[3.14] == 0 &&
175 map6[1.0] == 10 && map6[3.14] == 100,
176 "Something is wrong with SparseMap");
181 typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
182 checkConcept<ReadMap<B,double>, CompMap>();
183 CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
184 CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
186 SparseMap<double, bool> m1(false); m1[3.14] = true;
187 RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
188 check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
189 "Something is wrong with ComposeMap")
194 typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
195 checkConcept<ReadMap<A,double>, CombMap>();
196 CombMap map1 = CombMap(DoubleMap(), DoubleMap());
197 CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
199 check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
200 "Something is wrong with CombineMap");
203 // FunctorToMap, MapToFunctor
205 checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
206 checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
207 FunctorToMap<F> map1;
208 FunctorToMap<F> map2 = FunctorToMap<F>(F());
209 B b = functorToMap(F())[A()];
211 checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
212 MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
214 check(functorToMap(&func)[A()] == 3,
215 "Something is wrong with FunctorToMap");
216 check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
217 "Something is wrong with MapToFunctor");
218 check(mapToFunctor(functorToMap(&func))(A()) == 3 &&
219 mapToFunctor(functorToMap(&func))[A()] == 3,
220 "Something is wrong with FunctorToMap or MapToFunctor");
221 check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2,
222 "Something is wrong with FunctorToMap or MapToFunctor");
227 checkConcept<ReadMap<double,double>,
228 ConvertMap<ReadMap<double, int>, double> >();
229 ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
230 ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
235 checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
237 typedef RangeMap<double> RM;
238 typedef SparseMap<int, double> SM;
241 checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
242 checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >();
243 ForkMap<RM, SM> map1(m1,m2);
244 ForkMap<SM, RM> map2 = forkMap(m2,m1);
246 check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 &&
247 m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
248 "Something is wrong with ForkMap");
252 // - AddMap, SubMap, MulMap, DivMap
253 // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
254 // - NegMap, NegWriteMap, AbsMap
256 checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
257 checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
258 checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
259 checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
261 ConstMap<int, double> c1(1.0), c2(3.14);
263 ConvertMap<IdentityMap<int>, double> id(im);
264 check(addMap(c1,id)[0] == 1.0 && addMap(c1,id)[10] == 11.0,
265 "Something is wrong with AddMap");
266 check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,
267 "Something is wrong with SubMap");
268 check(mulMap(id,c2)[0] == 0 && mulMap(id,c2)[2] == 6.28,
269 "Something is wrong with MulMap");
270 check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2] == 1.57,
271 "Something is wrong with DivMap");
273 checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
274 checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
275 checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
276 checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
277 checkConcept<DoubleMap, NegMap<DoubleMap> >();
278 checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >();
279 checkConcept<DoubleMap, AbsMap<DoubleMap> >();
281 check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0,
282 "Something is wrong with ShiftMap");
283 check(shiftWriteMap(id, 2.0)[1] == 3.0 &&
284 shiftWriteMap(id, 2.0)[10] == 12.0,
285 "Something is wrong with ShiftWriteMap");
286 check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0,
287 "Something is wrong with ScaleMap");
288 check(scaleWriteMap(id, 2.0)[1] == 2.0 &&
289 scaleWriteMap(id, 2.0)[10] == 20.0,
290 "Something is wrong with ScaleWriteMap");
291 check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0,
292 "Something is wrong with NegMap");
293 check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
294 "Something is wrong with NegWriteMap");
295 check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
296 "Something is wrong with AbsMap");
300 // - TrueMap, FalseMap
302 // - NotMap, NotWriteMap
303 // - EqualMap, LessMap
305 checkConcept<BoolMap, TrueMap<A> >();
306 checkConcept<BoolMap, FalseMap<A> >();
307 checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
308 checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
309 checkConcept<BoolMap, NotMap<BoolMap> >();
310 checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
311 checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
312 checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
316 RangeMap<bool> rm(2);
317 rm[0] = true; rm[1] = false;
318 check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] &&
319 !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
320 "Something is wrong with AndMap");
321 check(orMap(tm,rm)[0] && orMap(tm,rm)[1] &&
322 orMap(fm,rm)[0] && !orMap(fm,rm)[1],
323 "Something is wrong with OrMap");
324 check(!notMap(rm)[0] && notMap(rm)[1],
325 "Something is wrong with NotMap");
326 check(!notWriteMap(rm)[0] && notWriteMap(rm)[1],
327 "Something is wrong with NotWriteMap");
329 ConstMap<int, double> cm(2.0);
331 ConvertMap<IdentityMap<int>, double> id(im);
332 check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
333 "Something is wrong with LessMap");
334 check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
335 "Something is wrong with EqualMap");
340 typedef std::vector<int> vec;
341 checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
342 checkConcept<WriteMap<int, bool>,
343 LoggerBoolMap<std::back_insert_iterator<vec> > >();
347 LoggerBoolMap<std::back_insert_iterator<vec> >
348 map1(std::back_inserter(v1));
349 LoggerBoolMap<vec::iterator> map2(v2.begin());
351 map1.set(20, true); map2.set(20, true);
352 map1.set(30, false); map2.set(40, false);
353 map1.set(50, true); map2.set(50, true);
354 map1.set(60, true); map2.set(60, true);
355 check(v1.size() == 3 && v2.size() == 10 &&
356 v1[0]==20 && v1[1]==50 && v1[2]==60 &&
357 v2[0]==20 && v2[1]==50 && v2[2]==60,
358 "Something is wrong with LoggerBoolMap");
361 for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
362 it != map2.end(); ++it )
363 check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
365 typedef ListDigraph Graph;
366 DIGRAPH_TYPEDEFS(Graph);
369 Node n0 = gr.addNode();
370 Node n1 = gr.addNode();
371 Node n2 = gr.addNode();
372 Node n3 = gr.addNode();
382 dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
384 check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
385 "Something is wrong with LoggerBoolMap");
388 std::vector<Node> v(countNodes(gr));
389 dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
391 check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
392 "Something is wrong with LoggerBoolMap");
398 typedef ListDigraph Graph;
399 DIGRAPH_TYPEDEFS(Graph);
401 checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
402 checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
403 checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
404 checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
407 IdMap<Graph, Node> nmap(gr);
408 IdMap<Graph, Arc> amap(gr);
409 RangeIdMap<Graph, Node> nrmap(gr);
410 RangeIdMap<Graph, Arc> armap(gr);
412 Node n0 = gr.addNode();
413 Node n1 = gr.addNode();
414 Node n2 = gr.addNode();
416 Arc a0 = gr.addArc(n0, n1);
417 Arc a1 = gr.addArc(n0, n2);
418 Arc a2 = gr.addArc(n2, n1);
419 Arc a3 = gr.addArc(n2, n0);
421 check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
422 check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
423 check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
425 check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
426 check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
427 check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
428 check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
430 check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
431 check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
433 check(nrmap.size() == 3 && armap.size() == 4,
434 "Wrong RangeIdMap::size()");
436 check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
437 check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
438 check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
440 check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
441 check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
442 check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
443 check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
445 check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
446 check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
450 if (nrmap[n0] == 1) nrmap.swap(n0, n2);
452 if (armap[a1] == 1) armap.swap(a1, a3);
455 check(nrmap.size() == 2 && armap.size() == 2,
456 "Wrong RangeIdMap::size()");
458 check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
459 check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
461 check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
462 check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
464 check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
465 check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
468 // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
470 typedef ListGraph Graph;
471 GRAPH_TYPEDEFS(Graph);
473 checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
474 checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
475 checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
476 checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
477 checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
478 checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
481 Node n0 = gr.addNode();
482 Node n1 = gr.addNode();
483 Node n2 = gr.addNode();
492 for (EdgeIt e(gr); e != INVALID; ++e) {
493 check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
494 check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
497 compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))),
498 targetMap(orienter(gr, constMap<Edge, bool>(false))),
501 typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
502 Digraph dgr(gr, constMap<Edge, bool>(true));
503 OutDegMap<Digraph> odm(dgr);
504 InDegMap<Digraph> idm(dgr);
506 check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
507 check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
511 check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
512 check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
517 typedef ListDigraph Graph;
518 DIGRAPH_TYPEDEFS(Graph);
520 checkConcept<ReadWriteMap<Node, int>,
521 CrossRefMap<Graph, Node, int> >();
522 checkConcept<ReadWriteMap<Node, bool>,
523 CrossRefMap<Graph, Node, bool> >();
524 checkConcept<ReadWriteMap<Node, double>,
525 CrossRefMap<Graph, Node, double> >();
528 typedef CrossRefMap<Graph, Node, char> CRMap;
531 Node n0 = gr.addNode();
532 Node n1 = gr.addNode();
533 Node n2 = gr.addNode();
539 check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
540 "Wrong CrossRefMap");
541 check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
542 "Wrong CrossRefMap");
543 check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
544 "Wrong CrossRefMap");
545 check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
546 "Wrong CrossRefMap::count()");
548 CRMap::ValueIt it = map.beginValue();
549 check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
550 it == map.endValue(), "Wrong value iterator");
554 check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
555 "Wrong CrossRefMap");
556 check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
557 check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
558 check(map('C') == INVALID && map.inverse()['C'] == INVALID,
559 "Wrong CrossRefMap");
560 check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
561 "Wrong CrossRefMap::count()");
563 it = map.beginValue();
564 check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
565 it == map.endValue(), "Wrong value iterator");
569 check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
570 "Wrong CrossRefMap");
571 check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
572 check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
573 check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
574 check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
575 "Wrong CrossRefMap::count()");
577 it = map.beginValue();
578 check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
579 it == map.endValue(), "Wrong value iterator");
584 typedef SmartGraph Graph;
585 typedef SmartGraph::Node Item;
587 typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
588 checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
592 std::vector<Item> items;
593 for (int i = 0; i < num; ++i) {
594 items.push_back(g.addNode());
599 for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
600 check(map1[static_cast<Item>(it)], "Wrong TrueIt");
603 check(n == num, "Wrong number");
606 for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
607 check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
610 check(n == num, "Wrong number");
611 check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
612 check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
614 map1[items[5]] = true;
617 for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
618 check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
621 check(n == num, "Wrong number");
623 map1[items[num / 2]] = false;
624 check(map1[items[num / 2]] == false, "Wrong map value");
627 for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
628 check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
631 check(n == num - 1, "Wrong number");
634 for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
635 check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
638 check(n == 1, "Wrong number");
640 map1[items[0]] = false;
641 check(map1[items[0]] == false, "Wrong map value");
643 map1[items[num - 1]] = false;
644 check(map1[items[num - 1]] == false, "Wrong map value");
647 for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
648 check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
651 check(n == num - 3, "Wrong number");
652 check(map1.trueNum() == num - 3, "Wrong number");
655 for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
656 check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
659 check(n == 3, "Wrong number");
660 check(map1.falseNum() == 3, "Wrong number");
665 typedef SmartGraph Graph;
666 typedef SmartGraph::Node Item;
667 typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
669 checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
673 std::vector<Item> items;
674 for (int i = 0; i < num; ++i) {
675 items.push_back(g.addNode());
679 check(map1.size() == 0, "Wrong size");
681 for (int i = 0; i < num; ++i) {
684 check(map1.size() == num, "Wrong size");
686 for (int i = 0; i < num; ++i) {
687 Iim::ItemIt it(map1, i);
688 check(static_cast<Item>(it) == items[i], "Wrong value");
690 check(static_cast<Item>(it) == INVALID, "Wrong value");
693 for (int i = 0; i < num; ++i) {
694 map1[items[i]] = i % 2;
696 check(map1.size() == 2, "Wrong size");
699 for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
700 check(map1[static_cast<Item>(it)] == 0, "Wrong value");
703 check(n == (num + 1) / 2, "Wrong number");
705 for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
706 check(map1[static_cast<Item>(it)] == 1, "Wrong value");
709 check(n == num, "Wrong number");
713 // Iterable value map
715 typedef SmartGraph Graph;
716 typedef SmartGraph::Node Item;
717 typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
719 checkConcept<ReadWriteMap<Item, double>, Ivm>();
723 std::vector<Item> items;
724 for (int i = 0; i < num; ++i) {
725 items.push_back(g.addNode());
729 check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
730 check(*map1.beginValue() == 0.0, "Wrong value");
732 for (int i = 0; i < num; ++i) {
733 map1.set(items[i], static_cast<double>(i));
735 check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
737 for (int i = 0; i < num; ++i) {
738 Ivm::ItemIt it(map1, static_cast<double>(i));
739 check(static_cast<Item>(it) == items[i], "Wrong value");
741 check(static_cast<Item>(it) == INVALID, "Wrong value");
744 for (Ivm::ValueIt vit = map1.beginValue();
745 vit != map1.endValue(); ++vit) {
746 check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
750 for (int i = 0; i < num; ++i) {
751 map1.set(items[i], static_cast<double>(i % 2));
753 check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
756 for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
757 check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
760 check(n == (num + 1) / 2, "Wrong number");
762 for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
763 check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
766 check(n == num, "Wrong number");