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>
28 #include "test_tools.h"
30 using namespace lemon;
31 using namespace lemon::concepts;
34 inline bool operator<(A, A) { return true; }
45 typedef A argument_type;
46 typedef B result_type;
48 B operator()(const A&) const { return B(); }
50 F& operator=(const F&);
53 int func(A) { return 3; }
55 int binc(int a, B) { return a+1; }
57 typedef ReadMap<A, double> DoubleMap;
58 typedef ReadWriteMap<A, double> DoubleWriteMap;
59 typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
61 typedef ReadMap<A, bool> BoolMap;
62 typedef ReadWriteMap<A, bool> BoolWriteMap;
63 typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
68 checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
69 checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
70 checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
71 checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
72 checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
73 checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
74 checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
75 checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
79 checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
81 NullMap<A,B> map2 = map1;
82 map1 = nullMap<A,B>();
87 checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
88 checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
90 ConstMap<A,B> map2 = B();
91 ConstMap<A,B> map3 = map1;
92 map1 = constMap<A>(B());
93 map1 = constMap<A,B>();
95 ConstMap<A,C> map4(C(1));
96 ConstMap<A,C> map5 = map4;
97 map4 = constMap<A>(C(2));
100 checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
101 check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
103 checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
104 ConstMap<A,Const<int,10> > map6;
105 ConstMap<A,Const<int,10> > map7 = map6;
106 map6 = constMap<A,int,10>();
107 map7 = constMap<A,Const<int,10> >();
108 check(map6[A()] == 10 && map7[A()] == 10,
109 "Something is wrong with ConstMap");
114 checkConcept<ReadMap<A,A>, IdentityMap<A> >();
116 IdentityMap<A> map2 = map1;
117 map1 = identityMap<A>();
119 checkConcept<ReadMap<double,double>, IdentityMap<double> >();
120 check(identityMap<double>()[1.0] == 1.0 &&
121 identityMap<double>()[3.14] == 3.14,
122 "Something is wrong with IdentityMap");
127 checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >();
129 RangeMap<B> map2(10);
130 RangeMap<B> map3(10,B());
131 RangeMap<B> map4 = map1;
132 RangeMap<B> map5 = rangeMap<B>();
133 RangeMap<B> map6 = rangeMap<B>(10);
134 RangeMap<B> map7 = rangeMap(10,B());
136 checkConcept< ReferenceMap<int, double, double&, const double&>,
137 RangeMap<double> >();
138 std::vector<double> v(10, 0);
140 RangeMap<double> map8(v);
141 RangeMap<double> map9 = rangeMap(v);
142 check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100,
143 "Something is wrong with RangeMap");
148 checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >();
150 SparseMap<A,B> map2 = B();
151 SparseMap<A,B> map3 = sparseMap<A,B>();
152 SparseMap<A,B> map4 = sparseMap<A>(B());
154 checkConcept< ReferenceMap<double, int, int&, const int&>,
155 SparseMap<double, int> >();
156 std::map<double, int> m;
157 SparseMap<double, int> map5(m);
158 SparseMap<double, int> map6(m,10);
159 SparseMap<double, int> map7 = sparseMap(m);
160 SparseMap<double, int> map8 = sparseMap(m,10);
162 check(map5[1.0] == 0 && map5[3.14] == 0 &&
163 map6[1.0] == 10 && map6[3.14] == 10,
164 "Something is wrong with SparseMap");
165 map5[1.0] = map6[3.14] = 100;
166 check(map5[1.0] == 100 && map5[3.14] == 0 &&
167 map6[1.0] == 10 && map6[3.14] == 100,
168 "Something is wrong with SparseMap");
173 typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
174 checkConcept<ReadMap<B,double>, CompMap>();
175 CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
176 CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
178 SparseMap<double, bool> m1(false); m1[3.14] = true;
179 RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
180 check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
181 "Something is wrong with ComposeMap")
186 typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
187 checkConcept<ReadMap<A,double>, CombMap>();
188 CombMap map1 = CombMap(DoubleMap(), DoubleMap());
189 CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
191 check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
192 "Something is wrong with CombineMap");
195 // FunctorToMap, MapToFunctor
197 checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
198 checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
199 FunctorToMap<F> map1;
200 FunctorToMap<F> map2 = FunctorToMap<F>(F());
201 B b = functorToMap(F())[A()];
203 checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
204 MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
206 check(functorToMap(&func)[A()] == 3,
207 "Something is wrong with FunctorToMap");
208 check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
209 "Something is wrong with MapToFunctor");
210 check(mapToFunctor(functorToMap(&func))(A()) == 3 &&
211 mapToFunctor(functorToMap(&func))[A()] == 3,
212 "Something is wrong with FunctorToMap or MapToFunctor");
213 check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2,
214 "Something is wrong with FunctorToMap or MapToFunctor");
219 checkConcept<ReadMap<double,double>,
220 ConvertMap<ReadMap<double, int>, double> >();
221 ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
222 ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
227 checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
229 typedef RangeMap<double> RM;
230 typedef SparseMap<int, double> SM;
233 checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
234 checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >();
235 ForkMap<RM, SM> map1(m1,m2);
236 ForkMap<SM, RM> map2 = forkMap(m2,m1);
238 check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 &&
239 m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
240 "Something is wrong with ForkMap");
244 // - AddMap, SubMap, MulMap, DivMap
245 // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
246 // - NegMap, NegWriteMap, AbsMap
248 checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
249 checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
250 checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
251 checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
253 ConstMap<int, double> c1(1.0), c2(3.14);
255 ConvertMap<IdentityMap<int>, double> id(im);
256 check(addMap(c1,id)[0] == 1.0 && addMap(c1,id)[10] == 11.0,
257 "Something is wrong with AddMap");
258 check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,
259 "Something is wrong with SubMap");
260 check(mulMap(id,c2)[0] == 0 && mulMap(id,c2)[2] == 6.28,
261 "Something is wrong with MulMap");
262 check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2] == 1.57,
263 "Something is wrong with DivMap");
265 checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
266 checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
267 checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
268 checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
269 checkConcept<DoubleMap, NegMap<DoubleMap> >();
270 checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >();
271 checkConcept<DoubleMap, AbsMap<DoubleMap> >();
273 check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0,
274 "Something is wrong with ShiftMap");
275 check(shiftWriteMap(id, 2.0)[1] == 3.0 &&
276 shiftWriteMap(id, 2.0)[10] == 12.0,
277 "Something is wrong with ShiftWriteMap");
278 check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0,
279 "Something is wrong with ScaleMap");
280 check(scaleWriteMap(id, 2.0)[1] == 2.0 &&
281 scaleWriteMap(id, 2.0)[10] == 20.0,
282 "Something is wrong with ScaleWriteMap");
283 check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0,
284 "Something is wrong with NegMap");
285 check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
286 "Something is wrong with NegWriteMap");
287 check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
288 "Something is wrong with AbsMap");
292 // - TrueMap, FalseMap
294 // - NotMap, NotWriteMap
295 // - EqualMap, LessMap
297 checkConcept<BoolMap, TrueMap<A> >();
298 checkConcept<BoolMap, FalseMap<A> >();
299 checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
300 checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
301 checkConcept<BoolMap, NotMap<BoolMap> >();
302 checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
303 checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
304 checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
308 RangeMap<bool> rm(2);
309 rm[0] = true; rm[1] = false;
310 check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] &&
311 !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
312 "Something is wrong with AndMap");
313 check(orMap(tm,rm)[0] && orMap(tm,rm)[1] &&
314 orMap(fm,rm)[0] && !orMap(fm,rm)[1],
315 "Something is wrong with OrMap");
316 check(!notMap(rm)[0] && notMap(rm)[1],
317 "Something is wrong with NotMap");
318 check(!notWriteMap(rm)[0] && notWriteMap(rm)[1],
319 "Something is wrong with NotWriteMap");
321 ConstMap<int, double> cm(2.0);
323 ConvertMap<IdentityMap<int>, double> id(im);
324 check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
325 "Something is wrong with LessMap");
326 check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
327 "Something is wrong with EqualMap");
332 typedef std::vector<int> vec;
333 checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
334 checkConcept<WriteMap<int, bool>,
335 LoggerBoolMap<std::back_insert_iterator<vec> > >();
339 LoggerBoolMap<std::back_insert_iterator<vec> >
340 map1(std::back_inserter(v1));
341 LoggerBoolMap<vec::iterator> map2(v2.begin());
343 map1.set(20, true); map2.set(20, true);
344 map1.set(30, false); map2.set(40, false);
345 map1.set(50, true); map2.set(50, true);
346 map1.set(60, true); map2.set(60, true);
347 check(v1.size() == 3 && v2.size() == 10 &&
348 v1[0]==20 && v1[1]==50 && v1[2]==60 &&
349 v2[0]==20 && v2[1]==50 && v2[2]==60,
350 "Something is wrong with LoggerBoolMap");
353 for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
354 it != map2.end(); ++it )
355 check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
360 typedef ListDigraph Graph;
361 DIGRAPH_TYPEDEFS(Graph);
363 checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
364 checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
365 checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
366 checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
369 IdMap<Graph, Node> nmap(gr);
370 IdMap<Graph, Arc> amap(gr);
371 RangeIdMap<Graph, Node> nrmap(gr);
372 RangeIdMap<Graph, Arc> armap(gr);
374 Node n0 = gr.addNode();
375 Node n1 = gr.addNode();
376 Node n2 = gr.addNode();
378 Arc a0 = gr.addArc(n0, n1);
379 Arc a1 = gr.addArc(n0, n2);
380 Arc a2 = gr.addArc(n2, n1);
381 Arc a3 = gr.addArc(n2, n0);
383 check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
384 check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
385 check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
387 check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
388 check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
389 check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
390 check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
392 check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
393 check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
395 check(nrmap.size() == 3 && armap.size() == 4,
396 "Wrong RangeIdMap::size()");
398 check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
399 check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
400 check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
402 check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
403 check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
404 check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
405 check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
407 check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
408 check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
412 if (nrmap[n0] == 1) nrmap.swap(n0, n2);
414 if (armap[a1] == 1) armap.swap(a1, a3);
417 check(nrmap.size() == 2 && armap.size() == 2,
418 "Wrong RangeIdMap::size()");
420 check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
421 check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
423 check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
424 check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
426 check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
427 check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
432 typedef ListDigraph Graph;
433 DIGRAPH_TYPEDEFS(Graph);
435 checkConcept<ReadWriteMap<Node, int>,
436 CrossRefMap<Graph, Node, int> >();
437 checkConcept<ReadWriteMap<Node, bool>,
438 CrossRefMap<Graph, Node, bool> >();
439 checkConcept<ReadWriteMap<Node, double>,
440 CrossRefMap<Graph, Node, double> >();
443 typedef CrossRefMap<Graph, Node, char> CRMap;
444 typedef CRMap::ValueIterator ValueIt;
447 Node n0 = gr.addNode();
448 Node n1 = gr.addNode();
449 Node n2 = gr.addNode();
455 check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
456 "Wrong CrossRefMap");
457 check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
458 "Wrong CrossRefMap");
459 check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
460 "Wrong CrossRefMap");
461 check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
462 "Wrong CrossRefMap::count()");
464 ValueIt it = map.beginValue();
465 check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
466 it == map.endValue(), "Wrong value iterator");
470 check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
471 "Wrong CrossRefMap");
472 check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
473 check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
474 check(map('C') == INVALID && map.inverse()['C'] == INVALID,
475 "Wrong CrossRefMap");
476 check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
477 "Wrong CrossRefMap::count()");
479 it = map.beginValue();
480 check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
481 it == map.endValue(), "Wrong value iterator");
485 check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
486 "Wrong CrossRefMap");
487 check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
488 check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
489 check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
490 check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
491 "Wrong CrossRefMap::count()");
493 it = map.beginValue();
494 check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
495 it == map.endValue(), "Wrong value iterator");
500 typedef SmartGraph Graph;
501 typedef SmartGraph::Node Item;
503 typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
504 checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
508 std::vector<Item> items;
509 for (int i = 0; i < num; ++i) {
510 items.push_back(g.addNode());
515 for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
516 check(map1[static_cast<Item>(it)], "Wrong TrueIt");
519 check(n == num, "Wrong number");
522 for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
523 check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
526 check(n == num, "Wrong number");
527 check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
528 check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
530 map1[items[5]] = true;
533 for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
534 check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
537 check(n == num, "Wrong number");
539 map1[items[num / 2]] = false;
540 check(map1[items[num / 2]] == false, "Wrong map value");
543 for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
544 check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
547 check(n == num - 1, "Wrong number");
550 for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
551 check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
554 check(n == 1, "Wrong number");
556 map1[items[0]] = false;
557 check(map1[items[0]] == false, "Wrong map value");
559 map1[items[num - 1]] = false;
560 check(map1[items[num - 1]] == false, "Wrong map value");
563 for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
564 check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
567 check(n == num - 3, "Wrong number");
568 check(map1.trueNum() == num - 3, "Wrong number");
571 for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
572 check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
575 check(n == 3, "Wrong number");
576 check(map1.falseNum() == 3, "Wrong number");
581 typedef SmartGraph Graph;
582 typedef SmartGraph::Node Item;
583 typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
585 checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
589 std::vector<Item> items;
590 for (int i = 0; i < num; ++i) {
591 items.push_back(g.addNode());
595 check(map1.size() == 0, "Wrong size");
597 for (int i = 0; i < num; ++i) {
600 check(map1.size() == num, "Wrong size");
602 for (int i = 0; i < num; ++i) {
603 Iim::ItemIt it(map1, i);
604 check(static_cast<Item>(it) == items[i], "Wrong value");
606 check(static_cast<Item>(it) == INVALID, "Wrong value");
609 for (int i = 0; i < num; ++i) {
610 map1[items[i]] = i % 2;
612 check(map1.size() == 2, "Wrong size");
615 for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
616 check(map1[static_cast<Item>(it)] == 0, "Wrong value");
619 check(n == (num + 1) / 2, "Wrong number");
621 for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
622 check(map1[static_cast<Item>(it)] == 1, "Wrong value");
625 check(n == num, "Wrong number");
629 // Iterable value map
631 typedef SmartGraph Graph;
632 typedef SmartGraph::Node Item;
633 typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
635 checkConcept<ReadWriteMap<Item, double>, Ivm>();
639 std::vector<Item> items;
640 for (int i = 0; i < num; ++i) {
641 items.push_back(g.addNode());
645 check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
646 check(*map1.beginValue() == 0.0, "Wrong value");
648 for (int i = 0; i < num; ++i) {
649 map1.set(items[i], static_cast<double>(i));
651 check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
653 for (int i = 0; i < num; ++i) {
654 Ivm::ItemIt it(map1, static_cast<double>(i));
655 check(static_cast<Item>(it) == items[i], "Wrong value");
657 check(static_cast<Item>(it) == INVALID, "Wrong value");
660 for (Ivm::ValueIterator vit = map1.beginValue();
661 vit != map1.endValue(); ++vit) {
662 check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
663 "Wrong ValueIterator");
666 for (int i = 0; i < num; ++i) {
667 map1.set(items[i], static_cast<double>(i % 2));
669 check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
672 for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
673 check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
676 check(n == (num + 1) / 2, "Wrong number");
678 for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
679 check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
682 check(n == num, "Wrong number");