test/maps_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 31 Aug 2009 10:03:23 +0200
changeset 708 5d313b76f323
parent 684 7b1a6e963018
parent 694 71939d63ae77
child 726 3fc2a801c39e
permissions -rw-r--r--
Merge
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     5  * Copyright (C) 2003-2009
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     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.
    12  *
    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
    15  * purpose.
    16  *
    17  */
    18 
    19 #include <deque>
    20 #include <set>
    21 
    22 #include <lemon/concept_check.h>
    23 #include <lemon/concepts/maps.h>
    24 #include <lemon/maps.h>
    25 #include <lemon/smart_graph.h>
    26 
    27 #include "test_tools.h"
    28 
    29 using namespace lemon;
    30 using namespace lemon::concepts;
    31 
    32 struct A {};
    33 inline bool operator<(A, A) { return true; }
    34 struct B {};
    35 
    36 class C {
    37   int x;
    38 public:
    39   C(int _x) : x(_x) {}
    40 };
    41 
    42 class F {
    43 public:
    44   typedef A argument_type;
    45   typedef B result_type;
    46 
    47   B operator()(const A&) const { return B(); }
    48 private:
    49   F& operator=(const F&);
    50 };
    51 
    52 int func(A) { return 3; }
    53 
    54 int binc(int a, B) { return a+1; }
    55 
    56 typedef ReadMap<A, double> DoubleMap;
    57 typedef ReadWriteMap<A, double> DoubleWriteMap;
    58 typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
    59 
    60 typedef ReadMap<A, bool> BoolMap;
    61 typedef ReadWriteMap<A, bool> BoolWriteMap;
    62 typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
    63 
    64 int main()
    65 {
    66   // Map concepts
    67   checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
    68   checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
    69   checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
    70   checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
    71   checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
    72   checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
    73   checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
    74   checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
    75 
    76   // NullMap
    77   {
    78     checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
    79     NullMap<A,B> map1;
    80     NullMap<A,B> map2 = map1;
    81     map1 = nullMap<A,B>();
    82   }
    83 
    84   // ConstMap
    85   {
    86     checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
    87     checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
    88     ConstMap<A,B> map1;
    89     ConstMap<A,B> map2 = B();
    90     ConstMap<A,B> map3 = map1;
    91     map1 = constMap<A>(B());
    92     map1 = constMap<A,B>();
    93     map1.setAll(B());
    94     ConstMap<A,C> map4(C(1));
    95     ConstMap<A,C> map5 = map4;
    96     map4 = constMap<A>(C(2));
    97     map4.setAll(C(3));
    98 
    99     checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
   100     check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
   101 
   102     checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
   103     ConstMap<A,Const<int,10> > map6;
   104     ConstMap<A,Const<int,10> > map7 = map6;
   105     map6 = constMap<A,int,10>();
   106     map7 = constMap<A,Const<int,10> >();
   107     check(map6[A()] == 10 && map7[A()] == 10,
   108           "Something is wrong with ConstMap");
   109   }
   110 
   111   // IdentityMap
   112   {
   113     checkConcept<ReadMap<A,A>, IdentityMap<A> >();
   114     IdentityMap<A> map1;
   115     IdentityMap<A> map2 = map1;
   116     map1 = identityMap<A>();
   117 
   118     checkConcept<ReadMap<double,double>, IdentityMap<double> >();
   119     check(identityMap<double>()[1.0] == 1.0 &&
   120           identityMap<double>()[3.14] == 3.14,
   121           "Something is wrong with IdentityMap");
   122   }
   123 
   124   // RangeMap
   125   {
   126     checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >();
   127     RangeMap<B> map1;
   128     RangeMap<B> map2(10);
   129     RangeMap<B> map3(10,B());
   130     RangeMap<B> map4 = map1;
   131     RangeMap<B> map5 = rangeMap<B>();
   132     RangeMap<B> map6 = rangeMap<B>(10);
   133     RangeMap<B> map7 = rangeMap(10,B());
   134 
   135     checkConcept< ReferenceMap<int, double, double&, const double&>,
   136                   RangeMap<double> >();
   137     std::vector<double> v(10, 0);
   138     v[5] = 100;
   139     RangeMap<double> map8(v);
   140     RangeMap<double> map9 = rangeMap(v);
   141     check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100,
   142           "Something is wrong with RangeMap");
   143   }
   144 
   145   // SparseMap
   146   {
   147     checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >();
   148     SparseMap<A,B> map1;
   149     SparseMap<A,B> map2 = B();
   150     SparseMap<A,B> map3 = sparseMap<A,B>();
   151     SparseMap<A,B> map4 = sparseMap<A>(B());
   152 
   153     checkConcept< ReferenceMap<double, int, int&, const int&>,
   154                   SparseMap<double, int> >();
   155     std::map<double, int> m;
   156     SparseMap<double, int> map5(m);
   157     SparseMap<double, int> map6(m,10);
   158     SparseMap<double, int> map7 = sparseMap(m);
   159     SparseMap<double, int> map8 = sparseMap(m,10);
   160 
   161     check(map5[1.0] == 0 && map5[3.14] == 0 &&
   162           map6[1.0] == 10 && map6[3.14] == 10,
   163           "Something is wrong with SparseMap");
   164     map5[1.0] = map6[3.14] = 100;
   165     check(map5[1.0] == 100 && map5[3.14] == 0 &&
   166           map6[1.0] == 10 && map6[3.14] == 100,
   167           "Something is wrong with SparseMap");
   168   }
   169 
   170   // ComposeMap
   171   {
   172     typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
   173     checkConcept<ReadMap<B,double>, CompMap>();
   174     CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
   175     CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
   176 
   177     SparseMap<double, bool> m1(false); m1[3.14] = true;
   178     RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
   179     check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
   180           "Something is wrong with ComposeMap")
   181   }
   182 
   183   // CombineMap
   184   {
   185     typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
   186     checkConcept<ReadMap<A,double>, CombMap>();
   187     CombMap map1 = CombMap(DoubleMap(), DoubleMap());
   188     CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
   189 
   190     check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
   191           "Something is wrong with CombineMap");
   192   }
   193 
   194   // FunctorToMap, MapToFunctor
   195   {
   196     checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
   197     checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
   198     FunctorToMap<F> map1;
   199     FunctorToMap<F> map2 = FunctorToMap<F>(F());
   200     B b = functorToMap(F())[A()];
   201 
   202     checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
   203     MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
   204 
   205     check(functorToMap(&func)[A()] == 3,
   206           "Something is wrong with FunctorToMap");
   207     check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
   208           "Something is wrong with MapToFunctor");
   209     check(mapToFunctor(functorToMap(&func))(A()) == 3 &&
   210           mapToFunctor(functorToMap(&func))[A()] == 3,
   211           "Something is wrong with FunctorToMap or MapToFunctor");
   212     check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2,
   213           "Something is wrong with FunctorToMap or MapToFunctor");
   214   }
   215 
   216   // ConvertMap
   217   {
   218     checkConcept<ReadMap<double,double>,
   219       ConvertMap<ReadMap<double, int>, double> >();
   220     ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
   221     ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
   222   }
   223 
   224   // ForkMap
   225   {
   226     checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
   227 
   228     typedef RangeMap<double> RM;
   229     typedef SparseMap<int, double> SM;
   230     RM m1(10, -1);
   231     SM m2(-1);
   232     checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
   233     checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >();
   234     ForkMap<RM, SM> map1(m1,m2);
   235     ForkMap<SM, RM> map2 = forkMap(m2,m1);
   236     map2.set(5, 10);
   237     check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 &&
   238           m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
   239           "Something is wrong with ForkMap");
   240   }
   241 
   242   // Arithmetic maps:
   243   // - AddMap, SubMap, MulMap, DivMap
   244   // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
   245   // - NegMap, NegWriteMap, AbsMap
   246   {
   247     checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
   248     checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
   249     checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
   250     checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
   251 
   252     ConstMap<int, double> c1(1.0), c2(3.14);
   253     IdentityMap<int> im;
   254     ConvertMap<IdentityMap<int>, double> id(im);
   255     check(addMap(c1,id)[0] == 1.0  && addMap(c1,id)[10] == 11.0,
   256           "Something is wrong with AddMap");
   257     check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,
   258           "Something is wrong with SubMap");
   259     check(mulMap(id,c2)[0] == 0    && mulMap(id,c2)[2]  == 6.28,
   260           "Something is wrong with MulMap");
   261     check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2]  == 1.57,
   262           "Something is wrong with DivMap");
   263 
   264     checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
   265     checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
   266     checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
   267     checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
   268     checkConcept<DoubleMap, NegMap<DoubleMap> >();
   269     checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >();
   270     checkConcept<DoubleMap, AbsMap<DoubleMap> >();
   271 
   272     check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0,
   273           "Something is wrong with ShiftMap");
   274     check(shiftWriteMap(id, 2.0)[1] == 3.0 &&
   275           shiftWriteMap(id, 2.0)[10] == 12.0,
   276           "Something is wrong with ShiftWriteMap");
   277     check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0,
   278           "Something is wrong with ScaleMap");
   279     check(scaleWriteMap(id, 2.0)[1] == 2.0 &&
   280           scaleWriteMap(id, 2.0)[10] == 20.0,
   281           "Something is wrong with ScaleWriteMap");
   282     check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0,
   283           "Something is wrong with NegMap");
   284     check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
   285           "Something is wrong with NegWriteMap");
   286     check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
   287           "Something is wrong with AbsMap");
   288   }
   289 
   290   // Logical maps:
   291   // - TrueMap, FalseMap
   292   // - AndMap, OrMap
   293   // - NotMap, NotWriteMap
   294   // - EqualMap, LessMap
   295   {
   296     checkConcept<BoolMap, TrueMap<A> >();
   297     checkConcept<BoolMap, FalseMap<A> >();
   298     checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
   299     checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
   300     checkConcept<BoolMap, NotMap<BoolMap> >();
   301     checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
   302     checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
   303     checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
   304 
   305     TrueMap<int> tm;
   306     FalseMap<int> fm;
   307     RangeMap<bool> rm(2);
   308     rm[0] = true; rm[1] = false;
   309     check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] &&
   310           !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
   311           "Something is wrong with AndMap");
   312     check(orMap(tm,rm)[0] && orMap(tm,rm)[1] &&
   313           orMap(fm,rm)[0] && !orMap(fm,rm)[1],
   314           "Something is wrong with OrMap");
   315     check(!notMap(rm)[0] && notMap(rm)[1],
   316           "Something is wrong with NotMap");
   317     check(!notWriteMap(rm)[0] && notWriteMap(rm)[1],
   318           "Something is wrong with NotWriteMap");
   319 
   320     ConstMap<int, double> cm(2.0);
   321     IdentityMap<int> im;
   322     ConvertMap<IdentityMap<int>, double> id(im);
   323     check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
   324           "Something is wrong with LessMap");
   325     check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
   326           "Something is wrong with EqualMap");
   327   }
   328 
   329   // LoggerBoolMap
   330   {
   331     typedef std::vector<int> vec;
   332     vec v1;
   333     vec v2(10);
   334     LoggerBoolMap<std::back_insert_iterator<vec> >
   335       map1(std::back_inserter(v1));
   336     LoggerBoolMap<vec::iterator> map2(v2.begin());
   337     map1.set(10, false);
   338     map1.set(20, true);   map2.set(20, true);
   339     map1.set(30, false);  map2.set(40, false);
   340     map1.set(50, true);   map2.set(50, true);
   341     map1.set(60, true);   map2.set(60, true);
   342     check(v1.size() == 3 && v2.size() == 10 &&
   343           v1[0]==20 && v1[1]==50 && v1[2]==60 &&
   344           v2[0]==20 && v2[1]==50 && v2[2]==60,
   345           "Something is wrong with LoggerBoolMap");
   346 
   347     int i = 0;
   348     for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
   349           it != map2.end(); ++it )
   350       check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
   351   }
   352 
   353   // CrossRefMap
   354   {
   355     typedef SmartDigraph Graph;
   356     DIGRAPH_TYPEDEFS(Graph);
   357 
   358     checkConcept<ReadWriteMap<Node, int>,
   359                  CrossRefMap<Graph, Node, int> >();
   360     
   361     Graph gr;
   362     typedef CrossRefMap<Graph, Node, char> CRMap;
   363     typedef CRMap::ValueIterator ValueIt;
   364     CRMap map(gr);
   365     
   366     Node n0 = gr.addNode();
   367     Node n1 = gr.addNode();
   368     Node n2 = gr.addNode();
   369     
   370     map.set(n0, 'A');
   371     map.set(n1, 'B');
   372     map.set(n2, 'C');
   373     map.set(n2, 'A');
   374     map.set(n0, 'C');
   375 
   376     check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
   377           "Wrong CrossRefMap");
   378     check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
   379     check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
   380     check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
   381 
   382     ValueIt it = map.beginValue();
   383     check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
   384           it == map.endValue(), "Wrong value iterator");
   385   }
   386   
   387   // Iterable bool map
   388   {
   389     typedef SmartGraph Graph;
   390     typedef SmartGraph::Node Item;
   391 
   392     typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
   393     checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
   394 
   395     const int num = 10;
   396     Graph g;
   397     std::vector<Item> items;
   398     for (int i = 0; i < num; ++i) {
   399       items.push_back(g.addNode());
   400     }
   401 
   402     Ibm map1(g, true);
   403     int n = 0;
   404     for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
   405       check(map1[static_cast<Item>(it)], "Wrong TrueIt");
   406       ++n;
   407     }
   408     check(n == num, "Wrong number");
   409 
   410     n = 0;
   411     for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
   412         check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
   413         ++n;
   414     }
   415     check(n == num, "Wrong number");
   416     check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
   417     check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
   418 
   419     map1[items[5]] = true;
   420 
   421     n = 0;
   422     for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
   423         check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
   424         ++n;
   425     }
   426     check(n == num, "Wrong number");
   427 
   428     map1[items[num / 2]] = false;
   429     check(map1[items[num / 2]] == false, "Wrong map value");
   430 
   431     n = 0;
   432     for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
   433         check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
   434         ++n;
   435     }
   436     check(n == num - 1, "Wrong number");
   437 
   438     n = 0;
   439     for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
   440         check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
   441         ++n;
   442     }
   443     check(n == 1, "Wrong number");
   444 
   445     map1[items[0]] = false;
   446     check(map1[items[0]] == false, "Wrong map value");
   447 
   448     map1[items[num - 1]] = false;
   449     check(map1[items[num - 1]] == false, "Wrong map value");
   450 
   451     n = 0;
   452     for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
   453         check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
   454         ++n;
   455     }
   456     check(n == num - 3, "Wrong number");
   457     check(map1.trueNum() == num - 3, "Wrong number");
   458 
   459     n = 0;
   460     for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
   461         check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
   462         ++n;
   463     }
   464     check(n == 3, "Wrong number");
   465     check(map1.falseNum() == 3, "Wrong number");
   466   }
   467 
   468   // Iterable int map
   469   {
   470     typedef SmartGraph Graph;
   471     typedef SmartGraph::Node Item;
   472     typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
   473 
   474     checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
   475 
   476     const int num = 10;
   477     Graph g;
   478     std::vector<Item> items;
   479     for (int i = 0; i < num; ++i) {
   480       items.push_back(g.addNode());
   481     }
   482 
   483     Iim map1(g);
   484     check(map1.size() == 0, "Wrong size");
   485 
   486     for (int i = 0; i < num; ++i) {
   487       map1[items[i]] = i;
   488     }
   489     check(map1.size() == num, "Wrong size");
   490 
   491     for (int i = 0; i < num; ++i) {
   492       Iim::ItemIt it(map1, i);
   493       check(static_cast<Item>(it) == items[i], "Wrong value");
   494       ++it;
   495       check(static_cast<Item>(it) == INVALID, "Wrong value");
   496     }
   497 
   498     for (int i = 0; i < num; ++i) {
   499       map1[items[i]] = i % 2;
   500     }
   501     check(map1.size() == 2, "Wrong size");
   502 
   503     int n = 0;
   504     for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
   505       check(map1[static_cast<Item>(it)] == 0, "Wrong value");
   506       ++n;
   507     }
   508     check(n == (num + 1) / 2, "Wrong number");
   509 
   510     for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
   511       check(map1[static_cast<Item>(it)] == 1, "Wrong value");
   512       ++n;
   513     }
   514     check(n == num, "Wrong number");
   515 
   516   }
   517 
   518   // Iterable value map
   519   {
   520     typedef SmartGraph Graph;
   521     typedef SmartGraph::Node Item;
   522     typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
   523 
   524     checkConcept<ReadWriteMap<Item, double>, Ivm>();
   525 
   526     const int num = 10;
   527     Graph g;
   528     std::vector<Item> items;
   529     for (int i = 0; i < num; ++i) {
   530       items.push_back(g.addNode());
   531     }
   532 
   533     Ivm map1(g, 0.0);
   534     check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
   535     check(*map1.beginValue() == 0.0, "Wrong value");
   536 
   537     for (int i = 0; i < num; ++i) {
   538       map1.set(items[i], static_cast<double>(i));
   539     }
   540     check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
   541 
   542     for (int i = 0; i < num; ++i) {
   543       Ivm::ItemIt it(map1, static_cast<double>(i));
   544       check(static_cast<Item>(it) == items[i], "Wrong value");
   545       ++it;
   546       check(static_cast<Item>(it) == INVALID, "Wrong value");
   547     }
   548 
   549     for (Ivm::ValueIterator vit = map1.beginValue();
   550          vit != map1.endValue(); ++vit) {
   551       check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
   552             "Wrong ValueIterator");
   553     }
   554 
   555     for (int i = 0; i < num; ++i) {
   556       map1.set(items[i], static_cast<double>(i % 2));
   557     }
   558     check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
   559 
   560     int n = 0;
   561     for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
   562       check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
   563       ++n;
   564     }
   565     check(n == (num + 1) / 2, "Wrong number");
   566 
   567     for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
   568       check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
   569       ++n;
   570     }
   571     check(n == num, "Wrong number");
   572 
   573   }
   574   return 0;
   575 }