test/maps_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Thu, 05 Nov 2009 06:26:18 +0100
changeset 757 9fbbd802020f
parent 724 d8073df341f6
parent 695 8dae88c5943e
child 789 8ddb7deabab9
permissions -rw-r--r--
Merge #184
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@25
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@25
     4
 *
alpar@440
     5
 * Copyright (C) 2003-2009
alpar@25
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@25
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@25
     8
 *
alpar@25
     9
 * Permission to use, modify and distribute this software is granted
alpar@25
    10
 * provided that this copyright notice appears in all copies. For
alpar@25
    11
 * precise terms see the accompanying LICENSE file.
alpar@25
    12
 *
alpar@25
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@25
    14
 * express or implied, and with no claim as to its suitability for any
alpar@25
    15
 * purpose.
alpar@25
    16
 *
alpar@25
    17
 */
alpar@25
    18
alpar@25
    19
#include <deque>
alpar@25
    20
#include <set>
alpar@25
    21
alpar@25
    22
#include <lemon/concept_check.h>
alpar@25
    23
#include <lemon/concepts/maps.h>
alpar@25
    24
#include <lemon/maps.h>
kpeter@684
    25
#include <lemon/list_graph.h>
kpeter@694
    26
#include <lemon/smart_graph.h>
kpeter@723
    27
#include <lemon/adaptors.h>
kpeter@723
    28
#include <lemon/dfs.h>
alpar@25
    29
alpar@25
    30
#include "test_tools.h"
alpar@25
    31
alpar@25
    32
using namespace lemon;
alpar@25
    33
using namespace lemon::concepts;
alpar@25
    34
alpar@25
    35
struct A {};
alpar@25
    36
inline bool operator<(A, A) { return true; }
alpar@25
    37
struct B {};
alpar@25
    38
kpeter@94
    39
class C {
kpeter@94
    40
  int x;
kpeter@94
    41
public:
kpeter@94
    42
  C(int _x) : x(_x) {}
kpeter@94
    43
};
kpeter@94
    44
alpar@25
    45
class F {
alpar@25
    46
public:
alpar@25
    47
  typedef A argument_type;
alpar@25
    48
  typedef B result_type;
alpar@25
    49
kpeter@80
    50
  B operator()(const A&) const { return B(); }
kpeter@80
    51
private:
kpeter@80
    52
  F& operator=(const F&);
alpar@25
    53
};
alpar@25
    54
kpeter@80
    55
int func(A) { return 3; }
alpar@25
    56
kpeter@80
    57
int binc(int a, B) { return a+1; }
alpar@25
    58
kpeter@80
    59
typedef ReadMap<A, double> DoubleMap;
kpeter@80
    60
typedef ReadWriteMap<A, double> DoubleWriteMap;
kpeter@80
    61
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
alpar@25
    62
kpeter@80
    63
typedef ReadMap<A, bool> BoolMap;
alpar@25
    64
typedef ReadWriteMap<A, bool> BoolWriteMap;
kpeter@80
    65
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
alpar@25
    66
kpeter@723
    67
template<typename Map1, typename Map2, typename ItemIt>
kpeter@723
    68
void compareMap(const Map1& map1, const Map2& map2, ItemIt it) {
kpeter@723
    69
  for (; it != INVALID; ++it)
kpeter@723
    70
    check(map1[it] == map2[it], "The maps are not equal");
kpeter@723
    71
}
kpeter@723
    72
alpar@25
    73
int main()
kpeter@80
    74
{
kpeter@80
    75
  // Map concepts
alpar@25
    76
  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
kpeter@94
    77
  checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
alpar@25
    78
  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
kpeter@94
    79
  checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
alpar@25
    80
  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
kpeter@94
    81
  checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
alpar@25
    82
  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
kpeter@94
    83
  checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
alpar@25
    84
kpeter@80
    85
  // NullMap
kpeter@80
    86
  {
kpeter@80
    87
    checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
kpeter@80
    88
    NullMap<A,B> map1;
kpeter@80
    89
    NullMap<A,B> map2 = map1;
kpeter@80
    90
    map1 = nullMap<A,B>();
kpeter@80
    91
  }
kpeter@80
    92
kpeter@80
    93
  // ConstMap
kpeter@80
    94
  {
kpeter@80
    95
    checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
kpeter@123
    96
    checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
kpeter@80
    97
    ConstMap<A,B> map1;
deba@136
    98
    ConstMap<A,B> map2 = B();
kpeter@80
    99
    ConstMap<A,B> map3 = map1;
kpeter@80
   100
    map1 = constMap<A>(B());
kpeter@123
   101
    map1 = constMap<A,B>();
kpeter@80
   102
    map1.setAll(B());
kpeter@123
   103
    ConstMap<A,C> map4(C(1));
kpeter@123
   104
    ConstMap<A,C> map5 = map4;
kpeter@123
   105
    map4 = constMap<A>(C(2));
kpeter@123
   106
    map4.setAll(C(3));
kpeter@82
   107
kpeter@80
   108
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
kpeter@80
   109
    check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
kpeter@80
   110
kpeter@80
   111
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
kpeter@123
   112
    ConstMap<A,Const<int,10> > map6;
kpeter@123
   113
    ConstMap<A,Const<int,10> > map7 = map6;
kpeter@123
   114
    map6 = constMap<A,int,10>();
kpeter@123
   115
    map7 = constMap<A,Const<int,10> >();
alpar@210
   116
    check(map6[A()] == 10 && map7[A()] == 10,
alpar@210
   117
          "Something is wrong with ConstMap");
kpeter@80
   118
  }
kpeter@80
   119
kpeter@80
   120
  // IdentityMap
kpeter@80
   121
  {
kpeter@80
   122
    checkConcept<ReadMap<A,A>, IdentityMap<A> >();
kpeter@80
   123
    IdentityMap<A> map1;
kpeter@80
   124
    IdentityMap<A> map2 = map1;
kpeter@80
   125
    map1 = identityMap<A>();
kpeter@82
   126
kpeter@80
   127
    checkConcept<ReadMap<double,double>, IdentityMap<double> >();
alpar@210
   128
    check(identityMap<double>()[1.0] == 1.0 &&
alpar@210
   129
          identityMap<double>()[3.14] == 3.14,
kpeter@80
   130
          "Something is wrong with IdentityMap");
kpeter@80
   131
  }
kpeter@80
   132
kpeter@80
   133
  // RangeMap
kpeter@80
   134
  {
kpeter@80
   135
    checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >();
kpeter@80
   136
    RangeMap<B> map1;
kpeter@80
   137
    RangeMap<B> map2(10);
kpeter@80
   138
    RangeMap<B> map3(10,B());
kpeter@80
   139
    RangeMap<B> map4 = map1;
kpeter@80
   140
    RangeMap<B> map5 = rangeMap<B>();
kpeter@80
   141
    RangeMap<B> map6 = rangeMap<B>(10);
kpeter@80
   142
    RangeMap<B> map7 = rangeMap(10,B());
kpeter@80
   143
kpeter@80
   144
    checkConcept< ReferenceMap<int, double, double&, const double&>,
kpeter@80
   145
                  RangeMap<double> >();
kpeter@80
   146
    std::vector<double> v(10, 0);
kpeter@80
   147
    v[5] = 100;
kpeter@80
   148
    RangeMap<double> map8(v);
kpeter@80
   149
    RangeMap<double> map9 = rangeMap(v);
kpeter@80
   150
    check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100,
kpeter@80
   151
          "Something is wrong with RangeMap");
kpeter@80
   152
  }
kpeter@80
   153
kpeter@80
   154
  // SparseMap
kpeter@80
   155
  {
kpeter@80
   156
    checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >();
kpeter@80
   157
    SparseMap<A,B> map1;
deba@136
   158
    SparseMap<A,B> map2 = B();
kpeter@80
   159
    SparseMap<A,B> map3 = sparseMap<A,B>();
kpeter@80
   160
    SparseMap<A,B> map4 = sparseMap<A>(B());
kpeter@80
   161
kpeter@80
   162
    checkConcept< ReferenceMap<double, int, int&, const int&>,
kpeter@80
   163
                  SparseMap<double, int> >();
kpeter@80
   164
    std::map<double, int> m;
kpeter@80
   165
    SparseMap<double, int> map5(m);
kpeter@80
   166
    SparseMap<double, int> map6(m,10);
kpeter@80
   167
    SparseMap<double, int> map7 = sparseMap(m);
kpeter@80
   168
    SparseMap<double, int> map8 = sparseMap(m,10);
kpeter@80
   169
alpar@210
   170
    check(map5[1.0] == 0 && map5[3.14] == 0 &&
alpar@210
   171
          map6[1.0] == 10 && map6[3.14] == 10,
kpeter@80
   172
          "Something is wrong with SparseMap");
kpeter@80
   173
    map5[1.0] = map6[3.14] = 100;
alpar@210
   174
    check(map5[1.0] == 100 && map5[3.14] == 0 &&
alpar@210
   175
          map6[1.0] == 10 && map6[3.14] == 100,
kpeter@80
   176
          "Something is wrong with SparseMap");
kpeter@80
   177
  }
kpeter@80
   178
kpeter@80
   179
  // ComposeMap
kpeter@80
   180
  {
kpeter@80
   181
    typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
kpeter@80
   182
    checkConcept<ReadMap<B,double>, CompMap>();
alpar@477
   183
    CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
kpeter@80
   184
    CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
kpeter@82
   185
kpeter@80
   186
    SparseMap<double, bool> m1(false); m1[3.14] = true;
kpeter@80
   187
    RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
alpar@210
   188
    check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
alpar@210
   189
          "Something is wrong with ComposeMap")
kpeter@80
   190
  }
kpeter@80
   191
kpeter@80
   192
  // CombineMap
kpeter@80
   193
  {
kpeter@80
   194
    typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
kpeter@80
   195
    checkConcept<ReadMap<A,double>, CombMap>();
alpar@477
   196
    CombMap map1 = CombMap(DoubleMap(), DoubleMap());
kpeter@80
   197
    CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
kpeter@80
   198
kpeter@80
   199
    check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
kpeter@80
   200
          "Something is wrong with CombineMap");
kpeter@80
   201
  }
kpeter@80
   202
kpeter@80
   203
  // FunctorToMap, MapToFunctor
kpeter@80
   204
  {
kpeter@80
   205
    checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
kpeter@80
   206
    checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
kpeter@80
   207
    FunctorToMap<F> map1;
alpar@477
   208
    FunctorToMap<F> map2 = FunctorToMap<F>(F());
kpeter@80
   209
    B b = functorToMap(F())[A()];
kpeter@80
   210
kpeter@80
   211
    checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
alpar@477
   212
    MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
kpeter@80
   213
alpar@210
   214
    check(functorToMap(&func)[A()] == 3,
alpar@210
   215
          "Something is wrong with FunctorToMap");
alpar@210
   216
    check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
alpar@210
   217
          "Something is wrong with MapToFunctor");
alpar@210
   218
    check(mapToFunctor(functorToMap(&func))(A()) == 3 &&
alpar@210
   219
          mapToFunctor(functorToMap(&func))[A()] == 3,
kpeter@80
   220
          "Something is wrong with FunctorToMap or MapToFunctor");
kpeter@80
   221
    check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2,
kpeter@80
   222
          "Something is wrong with FunctorToMap or MapToFunctor");
kpeter@80
   223
  }
kpeter@80
   224
kpeter@80
   225
  // ConvertMap
kpeter@80
   226
  {
alpar@210
   227
    checkConcept<ReadMap<double,double>,
alpar@210
   228
      ConvertMap<ReadMap<double, int>, double> >();
kpeter@80
   229
    ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
kpeter@80
   230
    ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
kpeter@80
   231
  }
kpeter@80
   232
kpeter@80
   233
  // ForkMap
kpeter@80
   234
  {
kpeter@80
   235
    checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
kpeter@82
   236
kpeter@80
   237
    typedef RangeMap<double> RM;
kpeter@80
   238
    typedef SparseMap<int, double> SM;
kpeter@80
   239
    RM m1(10, -1);
kpeter@80
   240
    SM m2(-1);
kpeter@80
   241
    checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
kpeter@80
   242
    checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >();
kpeter@80
   243
    ForkMap<RM, SM> map1(m1,m2);
kpeter@80
   244
    ForkMap<SM, RM> map2 = forkMap(m2,m1);
kpeter@80
   245
    map2.set(5, 10);
alpar@210
   246
    check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 &&
alpar@210
   247
          m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
kpeter@80
   248
          "Something is wrong with ForkMap");
kpeter@80
   249
  }
kpeter@82
   250
kpeter@80
   251
  // Arithmetic maps:
kpeter@80
   252
  // - AddMap, SubMap, MulMap, DivMap
kpeter@80
   253
  // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
kpeter@80
   254
  // - NegMap, NegWriteMap, AbsMap
kpeter@80
   255
  {
kpeter@80
   256
    checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
kpeter@80
   257
    checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
kpeter@80
   258
    checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
kpeter@80
   259
    checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
kpeter@82
   260
kpeter@80
   261
    ConstMap<int, double> c1(1.0), c2(3.14);
kpeter@80
   262
    IdentityMap<int> im;
kpeter@80
   263
    ConvertMap<IdentityMap<int>, double> id(im);
alpar@210
   264
    check(addMap(c1,id)[0] == 1.0  && addMap(c1,id)[10] == 11.0,
alpar@210
   265
          "Something is wrong with AddMap");
alpar@210
   266
    check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,
alpar@210
   267
          "Something is wrong with SubMap");
alpar@210
   268
    check(mulMap(id,c2)[0] == 0    && mulMap(id,c2)[2]  == 6.28,
alpar@210
   269
          "Something is wrong with MulMap");
alpar@210
   270
    check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2]  == 1.57,
alpar@210
   271
          "Something is wrong with DivMap");
kpeter@82
   272
kpeter@80
   273
    checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
kpeter@80
   274
    checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
kpeter@80
   275
    checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
kpeter@80
   276
    checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
kpeter@80
   277
    checkConcept<DoubleMap, NegMap<DoubleMap> >();
kpeter@80
   278
    checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >();
kpeter@80
   279
    checkConcept<DoubleMap, AbsMap<DoubleMap> >();
alpar@25
   280
kpeter@80
   281
    check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0,
kpeter@80
   282
          "Something is wrong with ShiftMap");
alpar@210
   283
    check(shiftWriteMap(id, 2.0)[1] == 3.0 &&
alpar@210
   284
          shiftWriteMap(id, 2.0)[10] == 12.0,
kpeter@80
   285
          "Something is wrong with ShiftWriteMap");
kpeter@80
   286
    check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0,
kpeter@80
   287
          "Something is wrong with ScaleMap");
alpar@210
   288
    check(scaleWriteMap(id, 2.0)[1] == 2.0 &&
alpar@210
   289
          scaleWriteMap(id, 2.0)[10] == 20.0,
kpeter@80
   290
          "Something is wrong with ScaleWriteMap");
kpeter@80
   291
    check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0,
kpeter@80
   292
          "Something is wrong with NegMap");
kpeter@80
   293
    check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
kpeter@80
   294
          "Something is wrong with NegWriteMap");
kpeter@80
   295
    check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
kpeter@80
   296
          "Something is wrong with AbsMap");
kpeter@80
   297
  }
kpeter@82
   298
kpeter@82
   299
  // Logical maps:
kpeter@82
   300
  // - TrueMap, FalseMap
kpeter@82
   301
  // - AndMap, OrMap
kpeter@82
   302
  // - NotMap, NotWriteMap
kpeter@82
   303
  // - EqualMap, LessMap
kpeter@80
   304
  {
kpeter@82
   305
    checkConcept<BoolMap, TrueMap<A> >();
kpeter@82
   306
    checkConcept<BoolMap, FalseMap<A> >();
kpeter@82
   307
    checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
kpeter@82
   308
    checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
kpeter@80
   309
    checkConcept<BoolMap, NotMap<BoolMap> >();
kpeter@80
   310
    checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
kpeter@82
   311
    checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
kpeter@82
   312
    checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
kpeter@82
   313
kpeter@82
   314
    TrueMap<int> tm;
kpeter@82
   315
    FalseMap<int> fm;
kpeter@80
   316
    RangeMap<bool> rm(2);
kpeter@80
   317
    rm[0] = true; rm[1] = false;
alpar@210
   318
    check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] &&
alpar@210
   319
          !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
kpeter@82
   320
          "Something is wrong with AndMap");
alpar@210
   321
    check(orMap(tm,rm)[0] && orMap(tm,rm)[1] &&
alpar@210
   322
          orMap(fm,rm)[0] && !orMap(fm,rm)[1],
kpeter@82
   323
          "Something is wrong with OrMap");
alpar@210
   324
    check(!notMap(rm)[0] && notMap(rm)[1],
alpar@210
   325
          "Something is wrong with NotMap");
alpar@210
   326
    check(!notWriteMap(rm)[0] && notWriteMap(rm)[1],
alpar@210
   327
          "Something is wrong with NotWriteMap");
kpeter@82
   328
kpeter@82
   329
    ConstMap<int, double> cm(2.0);
kpeter@82
   330
    IdentityMap<int> im;
kpeter@82
   331
    ConvertMap<IdentityMap<int>, double> id(im);
kpeter@82
   332
    check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
kpeter@82
   333
          "Something is wrong with LessMap");
kpeter@82
   334
    check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
kpeter@82
   335
          "Something is wrong with EqualMap");
kpeter@80
   336
  }
alpar@209
   337
kpeter@167
   338
  // LoggerBoolMap
kpeter@159
   339
  {
kpeter@159
   340
    typedef std::vector<int> vec;
kpeter@720
   341
    checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
kpeter@720
   342
    checkConcept<WriteMap<int, bool>,
kpeter@720
   343
                 LoggerBoolMap<std::back_insert_iterator<vec> > >();
kpeter@720
   344
kpeter@159
   345
    vec v1;
kpeter@159
   346
    vec v2(10);
alpar@210
   347
    LoggerBoolMap<std::back_insert_iterator<vec> >
alpar@210
   348
      map1(std::back_inserter(v1));
kpeter@167
   349
    LoggerBoolMap<vec::iterator> map2(v2.begin());
kpeter@159
   350
    map1.set(10, false);
kpeter@159
   351
    map1.set(20, true);   map2.set(20, true);
kpeter@159
   352
    map1.set(30, false);  map2.set(40, false);
kpeter@159
   353
    map1.set(50, true);   map2.set(50, true);
kpeter@159
   354
    map1.set(60, true);   map2.set(60, true);
kpeter@159
   355
    check(v1.size() == 3 && v2.size() == 10 &&
alpar@210
   356
          v1[0]==20 && v1[1]==50 && v1[2]==60 &&
alpar@210
   357
          v2[0]==20 && v2[1]==50 && v2[2]==60,
kpeter@167
   358
          "Something is wrong with LoggerBoolMap");
alpar@209
   359
kpeter@159
   360
    int i = 0;
kpeter@167
   361
    for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
kpeter@159
   362
          it != map2.end(); ++it )
kpeter@167
   363
      check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
kpeter@723
   364
    
kpeter@723
   365
    typedef ListDigraph Graph;
kpeter@723
   366
    DIGRAPH_TYPEDEFS(Graph);
kpeter@723
   367
    Graph gr;
kpeter@723
   368
kpeter@723
   369
    Node n0 = gr.addNode();
kpeter@723
   370
    Node n1 = gr.addNode();
kpeter@723
   371
    Node n2 = gr.addNode();
kpeter@723
   372
    Node n3 = gr.addNode();
kpeter@723
   373
    
kpeter@723
   374
    gr.addArc(n3, n0);
kpeter@723
   375
    gr.addArc(n3, n2);
kpeter@723
   376
    gr.addArc(n0, n2);
kpeter@723
   377
    gr.addArc(n2, n1);
kpeter@723
   378
    gr.addArc(n0, n1);
kpeter@723
   379
    
kpeter@723
   380
    {
kpeter@723
   381
      std::vector<Node> v;
kpeter@723
   382
      dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
kpeter@723
   383
kpeter@723
   384
      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
kpeter@723
   385
            "Something is wrong with LoggerBoolMap");
kpeter@723
   386
    }
kpeter@723
   387
    {
kpeter@723
   388
      std::vector<Node> v(countNodes(gr));
kpeter@723
   389
      dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
kpeter@723
   390
      
kpeter@723
   391
      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
kpeter@723
   392
            "Something is wrong with LoggerBoolMap");
kpeter@723
   393
    }
kpeter@694
   394
  }
kpeter@684
   395
  
kpeter@720
   396
  // IdMap, RangeIdMap
kpeter@720
   397
  {
kpeter@720
   398
    typedef ListDigraph Graph;
kpeter@720
   399
    DIGRAPH_TYPEDEFS(Graph);
kpeter@720
   400
kpeter@720
   401
    checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
kpeter@720
   402
    checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
kpeter@720
   403
    checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
kpeter@720
   404
    checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
kpeter@720
   405
    
kpeter@720
   406
    Graph gr;
kpeter@720
   407
    IdMap<Graph, Node> nmap(gr);
kpeter@720
   408
    IdMap<Graph, Arc> amap(gr);
kpeter@720
   409
    RangeIdMap<Graph, Node> nrmap(gr);
kpeter@720
   410
    RangeIdMap<Graph, Arc> armap(gr);
kpeter@720
   411
    
kpeter@720
   412
    Node n0 = gr.addNode();
kpeter@720
   413
    Node n1 = gr.addNode();
kpeter@720
   414
    Node n2 = gr.addNode();
kpeter@720
   415
    
kpeter@720
   416
    Arc a0 = gr.addArc(n0, n1);
kpeter@720
   417
    Arc a1 = gr.addArc(n0, n2);
kpeter@720
   418
    Arc a2 = gr.addArc(n2, n1);
kpeter@720
   419
    Arc a3 = gr.addArc(n2, n0);
kpeter@720
   420
    
kpeter@720
   421
    check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
kpeter@720
   422
    check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
kpeter@720
   423
    check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
kpeter@720
   424
kpeter@720
   425
    check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
kpeter@720
   426
    check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
kpeter@720
   427
    check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
kpeter@720
   428
    check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
kpeter@720
   429
kpeter@720
   430
    check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
kpeter@720
   431
    check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
kpeter@720
   432
    
kpeter@720
   433
    check(nrmap.size() == 3 && armap.size() == 4,
kpeter@720
   434
          "Wrong RangeIdMap::size()");
kpeter@720
   435
kpeter@720
   436
    check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
kpeter@720
   437
    check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
kpeter@720
   438
    check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
kpeter@720
   439
    
kpeter@720
   440
    check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
kpeter@720
   441
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
kpeter@720
   442
    check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
kpeter@720
   443
    check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
kpeter@720
   444
kpeter@720
   445
    check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
kpeter@720
   446
    check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
kpeter@720
   447
    
kpeter@720
   448
    gr.erase(n1);
kpeter@720
   449
    
kpeter@720
   450
    if (nrmap[n0] == 1) nrmap.swap(n0, n2);
kpeter@720
   451
    nrmap.swap(n2, n0);
kpeter@720
   452
    if (armap[a1] == 1) armap.swap(a1, a3);
kpeter@720
   453
    armap.swap(a3, a1);
kpeter@720
   454
    
kpeter@720
   455
    check(nrmap.size() == 2 && armap.size() == 2,
kpeter@720
   456
          "Wrong RangeIdMap::size()");
kpeter@720
   457
kpeter@720
   458
    check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
kpeter@720
   459
    check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
kpeter@720
   460
    
kpeter@720
   461
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
kpeter@720
   462
    check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
kpeter@720
   463
kpeter@720
   464
    check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
kpeter@720
   465
    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
kpeter@720
   466
  }
kpeter@720
   467
  
kpeter@723
   468
  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
kpeter@723
   469
  {
kpeter@723
   470
    typedef ListGraph Graph;
kpeter@723
   471
    GRAPH_TYPEDEFS(Graph);
kpeter@723
   472
    
kpeter@723
   473
    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
kpeter@723
   474
    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
kpeter@723
   475
    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
kpeter@723
   476
    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
kpeter@723
   477
    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
kpeter@723
   478
    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
kpeter@723
   479
kpeter@723
   480
    Graph gr;
kpeter@723
   481
    Node n0 = gr.addNode();
kpeter@723
   482
    Node n1 = gr.addNode();
kpeter@723
   483
    Node n2 = gr.addNode();
kpeter@723
   484
    
kpeter@723
   485
    gr.addEdge(n0,n1);
kpeter@723
   486
    gr.addEdge(n1,n2);
kpeter@723
   487
    gr.addEdge(n0,n2);
kpeter@723
   488
    gr.addEdge(n2,n1);
kpeter@723
   489
    gr.addEdge(n1,n2);
kpeter@723
   490
    gr.addEdge(n0,n1);
kpeter@723
   491
    
kpeter@723
   492
    for (EdgeIt e(gr); e != INVALID; ++e) {
kpeter@723
   493
      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
kpeter@723
   494
      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
kpeter@723
   495
    }
kpeter@723
   496
    
kpeter@723
   497
    compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))),
kpeter@723
   498
               targetMap(orienter(gr, constMap<Edge, bool>(false))),
kpeter@723
   499
               EdgeIt(gr));
kpeter@723
   500
kpeter@723
   501
    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
kpeter@723
   502
    Digraph dgr(gr, constMap<Edge, bool>(true));
kpeter@723
   503
    OutDegMap<Digraph> odm(dgr);
kpeter@723
   504
    InDegMap<Digraph> idm(dgr);
kpeter@723
   505
    
kpeter@723
   506
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
kpeter@723
   507
    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
kpeter@723
   508
   
kpeter@723
   509
    gr.addEdge(n2, n0);
kpeter@723
   510
kpeter@723
   511
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
kpeter@723
   512
    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
kpeter@723
   513
  }
kpeter@723
   514
  
kpeter@684
   515
  // CrossRefMap
kpeter@684
   516
  {
kpeter@684
   517
    typedef ListDigraph Graph;
kpeter@684
   518
    DIGRAPH_TYPEDEFS(Graph);
kpeter@684
   519
kpeter@684
   520
    checkConcept<ReadWriteMap<Node, int>,
kpeter@684
   521
                 CrossRefMap<Graph, Node, int> >();
kpeter@720
   522
    checkConcept<ReadWriteMap<Node, bool>,
kpeter@720
   523
                 CrossRefMap<Graph, Node, bool> >();
kpeter@720
   524
    checkConcept<ReadWriteMap<Node, double>,
kpeter@720
   525
                 CrossRefMap<Graph, Node, double> >();
kpeter@684
   526
    
kpeter@684
   527
    Graph gr;
kpeter@684
   528
    typedef CrossRefMap<Graph, Node, char> CRMap;
kpeter@684
   529
    CRMap map(gr);
kpeter@684
   530
    
kpeter@684
   531
    Node n0 = gr.addNode();
kpeter@684
   532
    Node n1 = gr.addNode();
kpeter@684
   533
    Node n2 = gr.addNode();
kpeter@684
   534
    
kpeter@684
   535
    map.set(n0, 'A');
kpeter@684
   536
    map.set(n1, 'B');
kpeter@684
   537
    map.set(n2, 'C');
kpeter@720
   538
    
kpeter@720
   539
    check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
kpeter@720
   540
          "Wrong CrossRefMap");
kpeter@720
   541
    check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
kpeter@720
   542
          "Wrong CrossRefMap");
kpeter@720
   543
    check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
kpeter@720
   544
          "Wrong CrossRefMap");
kpeter@720
   545
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
kpeter@720
   546
          "Wrong CrossRefMap::count()");
kpeter@720
   547
    
kpeter@724
   548
    CRMap::ValueIt it = map.beginValue();
kpeter@720
   549
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@720
   550
          it == map.endValue(), "Wrong value iterator");
kpeter@720
   551
    
kpeter@684
   552
    map.set(n2, 'A');
kpeter@720
   553
kpeter@720
   554
    check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
kpeter@720
   555
          "Wrong CrossRefMap");
kpeter@720
   556
    check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
kpeter@720
   557
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@720
   558
    check(map('C') == INVALID && map.inverse()['C'] == INVALID,
kpeter@720
   559
          "Wrong CrossRefMap");
kpeter@720
   560
    check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
kpeter@720
   561
          "Wrong CrossRefMap::count()");
kpeter@720
   562
kpeter@720
   563
    it = map.beginValue();
kpeter@720
   564
    check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
kpeter@720
   565
          it == map.endValue(), "Wrong value iterator");
kpeter@720
   566
kpeter@684
   567
    map.set(n0, 'C');
kpeter@684
   568
kpeter@684
   569
    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
kpeter@684
   570
          "Wrong CrossRefMap");
kpeter@684
   571
    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
kpeter@684
   572
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@684
   573
    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
kpeter@720
   574
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
kpeter@720
   575
          "Wrong CrossRefMap::count()");
kpeter@684
   576
kpeter@720
   577
    it = map.beginValue();
kpeter@684
   578
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@684
   579
          it == map.endValue(), "Wrong value iterator");
kpeter@159
   580
  }
alpar@25
   581
kpeter@684
   582
  // CrossRefMap
kpeter@684
   583
  {
alpar@695
   584
    typedef SmartDigraph Graph;
kpeter@684
   585
    DIGRAPH_TYPEDEFS(Graph);
kpeter@684
   586
kpeter@684
   587
    checkConcept<ReadWriteMap<Node, int>,
kpeter@684
   588
                 CrossRefMap<Graph, Node, int> >();
kpeter@684
   589
    
kpeter@684
   590
    Graph gr;
kpeter@684
   591
    typedef CrossRefMap<Graph, Node, char> CRMap;
kpeter@684
   592
    typedef CRMap::ValueIterator ValueIt;
kpeter@684
   593
    CRMap map(gr);
kpeter@684
   594
    
kpeter@684
   595
    Node n0 = gr.addNode();
kpeter@684
   596
    Node n1 = gr.addNode();
kpeter@684
   597
    Node n2 = gr.addNode();
kpeter@684
   598
    
kpeter@684
   599
    map.set(n0, 'A');
kpeter@684
   600
    map.set(n1, 'B');
kpeter@684
   601
    map.set(n2, 'C');
kpeter@684
   602
    map.set(n2, 'A');
kpeter@684
   603
    map.set(n0, 'C');
kpeter@684
   604
kpeter@684
   605
    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
kpeter@684
   606
          "Wrong CrossRefMap");
kpeter@684
   607
    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
kpeter@684
   608
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@684
   609
    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
kpeter@684
   610
kpeter@684
   611
    ValueIt it = map.beginValue();
kpeter@684
   612
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@684
   613
          it == map.endValue(), "Wrong value iterator");
kpeter@684
   614
  }
alpar@695
   615
  
deba@693
   616
  // Iterable bool map
deba@693
   617
  {
deba@693
   618
    typedef SmartGraph Graph;
deba@693
   619
    typedef SmartGraph::Node Item;
deba@693
   620
deba@693
   621
    typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
kpeter@694
   622
    checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
deba@693
   623
deba@693
   624
    const int num = 10;
deba@693
   625
    Graph g;
deba@693
   626
    std::vector<Item> items;
deba@693
   627
    for (int i = 0; i < num; ++i) {
deba@693
   628
      items.push_back(g.addNode());
deba@693
   629
    }
deba@693
   630
deba@693
   631
    Ibm map1(g, true);
deba@693
   632
    int n = 0;
deba@693
   633
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@693
   634
      check(map1[static_cast<Item>(it)], "Wrong TrueIt");
deba@693
   635
      ++n;
deba@693
   636
    }
deba@693
   637
    check(n == num, "Wrong number");
deba@693
   638
deba@693
   639
    n = 0;
deba@693
   640
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
deba@693
   641
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
deba@693
   642
        ++n;
deba@693
   643
    }
deba@693
   644
    check(n == num, "Wrong number");
deba@693
   645
    check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
deba@693
   646
    check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
deba@693
   647
deba@693
   648
    map1[items[5]] = true;
deba@693
   649
deba@693
   650
    n = 0;
deba@693
   651
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
deba@693
   652
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
deba@693
   653
        ++n;
deba@693
   654
    }
deba@693
   655
    check(n == num, "Wrong number");
deba@693
   656
deba@693
   657
    map1[items[num / 2]] = false;
deba@693
   658
    check(map1[items[num / 2]] == false, "Wrong map value");
deba@693
   659
deba@693
   660
    n = 0;
deba@693
   661
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@693
   662
        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
deba@693
   663
        ++n;
deba@693
   664
    }
deba@693
   665
    check(n == num - 1, "Wrong number");
deba@693
   666
deba@693
   667
    n = 0;
deba@693
   668
    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
deba@693
   669
        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
deba@693
   670
        ++n;
deba@693
   671
    }
deba@693
   672
    check(n == 1, "Wrong number");
deba@693
   673
deba@693
   674
    map1[items[0]] = false;
deba@693
   675
    check(map1[items[0]] == false, "Wrong map value");
deba@693
   676
deba@693
   677
    map1[items[num - 1]] = false;
deba@693
   678
    check(map1[items[num - 1]] == false, "Wrong map value");
deba@693
   679
deba@693
   680
    n = 0;
deba@693
   681
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@693
   682
        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
deba@693
   683
        ++n;
deba@693
   684
    }
deba@693
   685
    check(n == num - 3, "Wrong number");
deba@693
   686
    check(map1.trueNum() == num - 3, "Wrong number");
deba@693
   687
deba@693
   688
    n = 0;
deba@693
   689
    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
deba@693
   690
        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
deba@693
   691
        ++n;
deba@693
   692
    }
deba@693
   693
    check(n == 3, "Wrong number");
deba@693
   694
    check(map1.falseNum() == 3, "Wrong number");
deba@693
   695
  }
deba@693
   696
deba@693
   697
  // Iterable int map
deba@693
   698
  {
deba@693
   699
    typedef SmartGraph Graph;
deba@693
   700
    typedef SmartGraph::Node Item;
deba@693
   701
    typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
deba@693
   702
kpeter@694
   703
    checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
deba@693
   704
deba@693
   705
    const int num = 10;
deba@693
   706
    Graph g;
deba@693
   707
    std::vector<Item> items;
deba@693
   708
    for (int i = 0; i < num; ++i) {
deba@693
   709
      items.push_back(g.addNode());
deba@693
   710
    }
deba@693
   711
deba@693
   712
    Iim map1(g);
deba@693
   713
    check(map1.size() == 0, "Wrong size");
deba@693
   714
deba@693
   715
    for (int i = 0; i < num; ++i) {
deba@693
   716
      map1[items[i]] = i;
deba@693
   717
    }
deba@693
   718
    check(map1.size() == num, "Wrong size");
deba@693
   719
deba@693
   720
    for (int i = 0; i < num; ++i) {
deba@693
   721
      Iim::ItemIt it(map1, i);
deba@693
   722
      check(static_cast<Item>(it) == items[i], "Wrong value");
deba@693
   723
      ++it;
deba@693
   724
      check(static_cast<Item>(it) == INVALID, "Wrong value");
deba@693
   725
    }
deba@693
   726
deba@693
   727
    for (int i = 0; i < num; ++i) {
deba@693
   728
      map1[items[i]] = i % 2;
deba@693
   729
    }
deba@693
   730
    check(map1.size() == 2, "Wrong size");
deba@693
   731
deba@693
   732
    int n = 0;
deba@693
   733
    for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
kpeter@694
   734
      check(map1[static_cast<Item>(it)] == 0, "Wrong value");
deba@693
   735
      ++n;
deba@693
   736
    }
deba@693
   737
    check(n == (num + 1) / 2, "Wrong number");
deba@693
   738
deba@693
   739
    for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
kpeter@694
   740
      check(map1[static_cast<Item>(it)] == 1, "Wrong value");
deba@693
   741
      ++n;
deba@693
   742
    }
deba@693
   743
    check(n == num, "Wrong number");
deba@693
   744
deba@693
   745
  }
deba@693
   746
deba@693
   747
  // Iterable value map
deba@693
   748
  {
deba@693
   749
    typedef SmartGraph Graph;
deba@693
   750
    typedef SmartGraph::Node Item;
deba@693
   751
    typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
deba@693
   752
deba@693
   753
    checkConcept<ReadWriteMap<Item, double>, Ivm>();
deba@693
   754
deba@693
   755
    const int num = 10;
deba@693
   756
    Graph g;
deba@693
   757
    std::vector<Item> items;
deba@693
   758
    for (int i = 0; i < num; ++i) {
deba@693
   759
      items.push_back(g.addNode());
deba@693
   760
    }
deba@693
   761
deba@693
   762
    Ivm map1(g, 0.0);
deba@693
   763
    check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
deba@693
   764
    check(*map1.beginValue() == 0.0, "Wrong value");
deba@693
   765
deba@693
   766
    for (int i = 0; i < num; ++i) {
deba@693
   767
      map1.set(items[i], static_cast<double>(i));
deba@693
   768
    }
deba@693
   769
    check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
deba@693
   770
deba@693
   771
    for (int i = 0; i < num; ++i) {
deba@693
   772
      Ivm::ItemIt it(map1, static_cast<double>(i));
deba@693
   773
      check(static_cast<Item>(it) == items[i], "Wrong value");
deba@693
   774
      ++it;
deba@693
   775
      check(static_cast<Item>(it) == INVALID, "Wrong value");
deba@693
   776
    }
deba@693
   777
kpeter@724
   778
    for (Ivm::ValueIt vit = map1.beginValue();
deba@693
   779
         vit != map1.endValue(); ++vit) {
deba@693
   780
      check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
kpeter@724
   781
            "Wrong ValueIt");
deba@693
   782
    }
deba@693
   783
deba@693
   784
    for (int i = 0; i < num; ++i) {
deba@693
   785
      map1.set(items[i], static_cast<double>(i % 2));
deba@693
   786
    }
deba@693
   787
    check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
deba@693
   788
deba@693
   789
    int n = 0;
deba@693
   790
    for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
kpeter@694
   791
      check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
deba@693
   792
      ++n;
deba@693
   793
    }
deba@693
   794
    check(n == (num + 1) / 2, "Wrong number");
deba@693
   795
deba@693
   796
    for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
kpeter@694
   797
      check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
deba@693
   798
      ++n;
deba@693
   799
    }
deba@693
   800
    check(n == num, "Wrong number");
deba@693
   801
deba@693
   802
  }
alpar@25
   803
  return 0;
alpar@25
   804
}