test/maps_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Thu, 05 Nov 2009 10:23:16 +0100
changeset 827 580af8cf2f6a
parent 771 d8073df341f6
parent 742 8dae88c5943e
child 836 8ddb7deabab9
permissions -rw-r--r--
Merge #68 (Port static graph implementation)
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@463
     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@731
    25
#include <lemon/list_graph.h>
kpeter@741
    26
#include <lemon/smart_graph.h>
kpeter@770
    27
#include <lemon/adaptors.h>
kpeter@770
    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@770
    67
template<typename Map1, typename Map2, typename ItemIt>
kpeter@770
    68
void compareMap(const Map1& map1, const Map2& map2, ItemIt it) {
kpeter@770
    69
  for (; it != INVALID; ++it)
kpeter@770
    70
    check(map1[it] == map2[it], "The maps are not equal");
kpeter@770
    71
}
kpeter@770
    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@554
   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@554
   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@554
   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@554
   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@767
   341
    checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
kpeter@767
   342
    checkConcept<WriteMap<int, bool>,
kpeter@767
   343
                 LoggerBoolMap<std::back_insert_iterator<vec> > >();
kpeter@767
   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@770
   364
    
kpeter@770
   365
    typedef ListDigraph Graph;
kpeter@770
   366
    DIGRAPH_TYPEDEFS(Graph);
kpeter@770
   367
    Graph gr;
kpeter@770
   368
kpeter@770
   369
    Node n0 = gr.addNode();
kpeter@770
   370
    Node n1 = gr.addNode();
kpeter@770
   371
    Node n2 = gr.addNode();
kpeter@770
   372
    Node n3 = gr.addNode();
kpeter@770
   373
    
kpeter@770
   374
    gr.addArc(n3, n0);
kpeter@770
   375
    gr.addArc(n3, n2);
kpeter@770
   376
    gr.addArc(n0, n2);
kpeter@770
   377
    gr.addArc(n2, n1);
kpeter@770
   378
    gr.addArc(n0, n1);
kpeter@770
   379
    
kpeter@770
   380
    {
kpeter@770
   381
      std::vector<Node> v;
kpeter@770
   382
      dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
kpeter@770
   383
kpeter@770
   384
      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
kpeter@770
   385
            "Something is wrong with LoggerBoolMap");
kpeter@770
   386
    }
kpeter@770
   387
    {
kpeter@770
   388
      std::vector<Node> v(countNodes(gr));
kpeter@770
   389
      dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
kpeter@770
   390
      
kpeter@770
   391
      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
kpeter@770
   392
            "Something is wrong with LoggerBoolMap");
kpeter@770
   393
    }
kpeter@741
   394
  }
kpeter@731
   395
  
kpeter@767
   396
  // IdMap, RangeIdMap
kpeter@767
   397
  {
kpeter@767
   398
    typedef ListDigraph Graph;
kpeter@767
   399
    DIGRAPH_TYPEDEFS(Graph);
kpeter@767
   400
kpeter@767
   401
    checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
kpeter@767
   402
    checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
kpeter@767
   403
    checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
kpeter@767
   404
    checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
kpeter@767
   405
    
kpeter@767
   406
    Graph gr;
kpeter@767
   407
    IdMap<Graph, Node> nmap(gr);
kpeter@767
   408
    IdMap<Graph, Arc> amap(gr);
kpeter@767
   409
    RangeIdMap<Graph, Node> nrmap(gr);
kpeter@767
   410
    RangeIdMap<Graph, Arc> armap(gr);
kpeter@767
   411
    
kpeter@767
   412
    Node n0 = gr.addNode();
kpeter@767
   413
    Node n1 = gr.addNode();
kpeter@767
   414
    Node n2 = gr.addNode();
kpeter@767
   415
    
kpeter@767
   416
    Arc a0 = gr.addArc(n0, n1);
kpeter@767
   417
    Arc a1 = gr.addArc(n0, n2);
kpeter@767
   418
    Arc a2 = gr.addArc(n2, n1);
kpeter@767
   419
    Arc a3 = gr.addArc(n2, n0);
kpeter@767
   420
    
kpeter@767
   421
    check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
kpeter@767
   422
    check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
kpeter@767
   423
    check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
kpeter@767
   424
kpeter@767
   425
    check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
kpeter@767
   426
    check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
kpeter@767
   427
    check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
kpeter@767
   428
    check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
kpeter@767
   429
kpeter@767
   430
    check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
kpeter@767
   431
    check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
kpeter@767
   432
    
kpeter@767
   433
    check(nrmap.size() == 3 && armap.size() == 4,
kpeter@767
   434
          "Wrong RangeIdMap::size()");
kpeter@767
   435
kpeter@767
   436
    check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
kpeter@767
   437
    check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
kpeter@767
   438
    check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
kpeter@767
   439
    
kpeter@767
   440
    check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
kpeter@767
   441
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
kpeter@767
   442
    check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
kpeter@767
   443
    check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
kpeter@767
   444
kpeter@767
   445
    check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
kpeter@767
   446
    check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
kpeter@767
   447
    
kpeter@767
   448
    gr.erase(n1);
kpeter@767
   449
    
kpeter@767
   450
    if (nrmap[n0] == 1) nrmap.swap(n0, n2);
kpeter@767
   451
    nrmap.swap(n2, n0);
kpeter@767
   452
    if (armap[a1] == 1) armap.swap(a1, a3);
kpeter@767
   453
    armap.swap(a3, a1);
kpeter@767
   454
    
kpeter@767
   455
    check(nrmap.size() == 2 && armap.size() == 2,
kpeter@767
   456
          "Wrong RangeIdMap::size()");
kpeter@767
   457
kpeter@767
   458
    check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
kpeter@767
   459
    check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
kpeter@767
   460
    
kpeter@767
   461
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
kpeter@767
   462
    check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
kpeter@767
   463
kpeter@767
   464
    check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
kpeter@767
   465
    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
kpeter@767
   466
  }
kpeter@767
   467
  
kpeter@770
   468
  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
kpeter@770
   469
  {
kpeter@770
   470
    typedef ListGraph Graph;
kpeter@770
   471
    GRAPH_TYPEDEFS(Graph);
kpeter@770
   472
    
kpeter@770
   473
    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
kpeter@770
   474
    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
kpeter@770
   475
    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
kpeter@770
   476
    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
kpeter@770
   477
    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
kpeter@770
   478
    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
kpeter@770
   479
kpeter@770
   480
    Graph gr;
kpeter@770
   481
    Node n0 = gr.addNode();
kpeter@770
   482
    Node n1 = gr.addNode();
kpeter@770
   483
    Node n2 = gr.addNode();
kpeter@770
   484
    
kpeter@770
   485
    gr.addEdge(n0,n1);
kpeter@770
   486
    gr.addEdge(n1,n2);
kpeter@770
   487
    gr.addEdge(n0,n2);
kpeter@770
   488
    gr.addEdge(n2,n1);
kpeter@770
   489
    gr.addEdge(n1,n2);
kpeter@770
   490
    gr.addEdge(n0,n1);
kpeter@770
   491
    
kpeter@770
   492
    for (EdgeIt e(gr); e != INVALID; ++e) {
kpeter@770
   493
      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
kpeter@770
   494
      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
kpeter@770
   495
    }
kpeter@770
   496
    
kpeter@770
   497
    compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))),
kpeter@770
   498
               targetMap(orienter(gr, constMap<Edge, bool>(false))),
kpeter@770
   499
               EdgeIt(gr));
kpeter@770
   500
kpeter@770
   501
    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
kpeter@770
   502
    Digraph dgr(gr, constMap<Edge, bool>(true));
kpeter@770
   503
    OutDegMap<Digraph> odm(dgr);
kpeter@770
   504
    InDegMap<Digraph> idm(dgr);
kpeter@770
   505
    
kpeter@770
   506
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
kpeter@770
   507
    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
kpeter@770
   508
   
kpeter@770
   509
    gr.addEdge(n2, n0);
kpeter@770
   510
kpeter@770
   511
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
kpeter@770
   512
    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
kpeter@770
   513
  }
kpeter@770
   514
  
kpeter@731
   515
  // CrossRefMap
kpeter@731
   516
  {
kpeter@731
   517
    typedef ListDigraph Graph;
kpeter@731
   518
    DIGRAPH_TYPEDEFS(Graph);
kpeter@731
   519
kpeter@731
   520
    checkConcept<ReadWriteMap<Node, int>,
kpeter@731
   521
                 CrossRefMap<Graph, Node, int> >();
kpeter@767
   522
    checkConcept<ReadWriteMap<Node, bool>,
kpeter@767
   523
                 CrossRefMap<Graph, Node, bool> >();
kpeter@767
   524
    checkConcept<ReadWriteMap<Node, double>,
kpeter@767
   525
                 CrossRefMap<Graph, Node, double> >();
kpeter@731
   526
    
kpeter@731
   527
    Graph gr;
kpeter@731
   528
    typedef CrossRefMap<Graph, Node, char> CRMap;
kpeter@731
   529
    CRMap map(gr);
kpeter@731
   530
    
kpeter@731
   531
    Node n0 = gr.addNode();
kpeter@731
   532
    Node n1 = gr.addNode();
kpeter@731
   533
    Node n2 = gr.addNode();
kpeter@731
   534
    
kpeter@731
   535
    map.set(n0, 'A');
kpeter@731
   536
    map.set(n1, 'B');
kpeter@731
   537
    map.set(n2, 'C');
kpeter@767
   538
    
kpeter@767
   539
    check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
kpeter@767
   540
          "Wrong CrossRefMap");
kpeter@767
   541
    check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
kpeter@767
   542
          "Wrong CrossRefMap");
kpeter@767
   543
    check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
kpeter@767
   544
          "Wrong CrossRefMap");
kpeter@767
   545
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
kpeter@767
   546
          "Wrong CrossRefMap::count()");
kpeter@767
   547
    
kpeter@771
   548
    CRMap::ValueIt it = map.beginValue();
kpeter@767
   549
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@767
   550
          it == map.endValue(), "Wrong value iterator");
kpeter@767
   551
    
kpeter@731
   552
    map.set(n2, 'A');
kpeter@767
   553
kpeter@767
   554
    check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
kpeter@767
   555
          "Wrong CrossRefMap");
kpeter@767
   556
    check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
kpeter@767
   557
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@767
   558
    check(map('C') == INVALID && map.inverse()['C'] == INVALID,
kpeter@767
   559
          "Wrong CrossRefMap");
kpeter@767
   560
    check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
kpeter@767
   561
          "Wrong CrossRefMap::count()");
kpeter@767
   562
kpeter@767
   563
    it = map.beginValue();
kpeter@767
   564
    check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
kpeter@767
   565
          it == map.endValue(), "Wrong value iterator");
kpeter@767
   566
kpeter@731
   567
    map.set(n0, 'C');
kpeter@731
   568
kpeter@731
   569
    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
kpeter@731
   570
          "Wrong CrossRefMap");
kpeter@731
   571
    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
kpeter@731
   572
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@731
   573
    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
kpeter@767
   574
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
kpeter@767
   575
          "Wrong CrossRefMap::count()");
kpeter@731
   576
kpeter@767
   577
    it = map.beginValue();
kpeter@731
   578
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@731
   579
          it == map.endValue(), "Wrong value iterator");
kpeter@159
   580
  }
alpar@25
   581
kpeter@731
   582
  // CrossRefMap
kpeter@731
   583
  {
alpar@742
   584
    typedef SmartDigraph Graph;
kpeter@731
   585
    DIGRAPH_TYPEDEFS(Graph);
kpeter@731
   586
kpeter@731
   587
    checkConcept<ReadWriteMap<Node, int>,
kpeter@731
   588
                 CrossRefMap<Graph, Node, int> >();
kpeter@731
   589
    
kpeter@731
   590
    Graph gr;
kpeter@731
   591
    typedef CrossRefMap<Graph, Node, char> CRMap;
kpeter@731
   592
    typedef CRMap::ValueIterator ValueIt;
kpeter@731
   593
    CRMap map(gr);
kpeter@731
   594
    
kpeter@731
   595
    Node n0 = gr.addNode();
kpeter@731
   596
    Node n1 = gr.addNode();
kpeter@731
   597
    Node n2 = gr.addNode();
kpeter@731
   598
    
kpeter@731
   599
    map.set(n0, 'A');
kpeter@731
   600
    map.set(n1, 'B');
kpeter@731
   601
    map.set(n2, 'C');
kpeter@731
   602
    map.set(n2, 'A');
kpeter@731
   603
    map.set(n0, 'C');
kpeter@731
   604
kpeter@731
   605
    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
kpeter@731
   606
          "Wrong CrossRefMap");
kpeter@731
   607
    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
kpeter@731
   608
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@731
   609
    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
kpeter@731
   610
kpeter@731
   611
    ValueIt it = map.beginValue();
kpeter@731
   612
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@731
   613
          it == map.endValue(), "Wrong value iterator");
kpeter@731
   614
  }
alpar@742
   615
  
deba@740
   616
  // Iterable bool map
deba@740
   617
  {
deba@740
   618
    typedef SmartGraph Graph;
deba@740
   619
    typedef SmartGraph::Node Item;
deba@740
   620
deba@740
   621
    typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
kpeter@741
   622
    checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
deba@740
   623
deba@740
   624
    const int num = 10;
deba@740
   625
    Graph g;
deba@740
   626
    std::vector<Item> items;
deba@740
   627
    for (int i = 0; i < num; ++i) {
deba@740
   628
      items.push_back(g.addNode());
deba@740
   629
    }
deba@740
   630
deba@740
   631
    Ibm map1(g, true);
deba@740
   632
    int n = 0;
deba@740
   633
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@740
   634
      check(map1[static_cast<Item>(it)], "Wrong TrueIt");
deba@740
   635
      ++n;
deba@740
   636
    }
deba@740
   637
    check(n == num, "Wrong number");
deba@740
   638
deba@740
   639
    n = 0;
deba@740
   640
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
deba@740
   641
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
deba@740
   642
        ++n;
deba@740
   643
    }
deba@740
   644
    check(n == num, "Wrong number");
deba@740
   645
    check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
deba@740
   646
    check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
deba@740
   647
deba@740
   648
    map1[items[5]] = true;
deba@740
   649
deba@740
   650
    n = 0;
deba@740
   651
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
deba@740
   652
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
deba@740
   653
        ++n;
deba@740
   654
    }
deba@740
   655
    check(n == num, "Wrong number");
deba@740
   656
deba@740
   657
    map1[items[num / 2]] = false;
deba@740
   658
    check(map1[items[num / 2]] == false, "Wrong map value");
deba@740
   659
deba@740
   660
    n = 0;
deba@740
   661
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@740
   662
        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
deba@740
   663
        ++n;
deba@740
   664
    }
deba@740
   665
    check(n == num - 1, "Wrong number");
deba@740
   666
deba@740
   667
    n = 0;
deba@740
   668
    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
deba@740
   669
        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
deba@740
   670
        ++n;
deba@740
   671
    }
deba@740
   672
    check(n == 1, "Wrong number");
deba@740
   673
deba@740
   674
    map1[items[0]] = false;
deba@740
   675
    check(map1[items[0]] == false, "Wrong map value");
deba@740
   676
deba@740
   677
    map1[items[num - 1]] = false;
deba@740
   678
    check(map1[items[num - 1]] == false, "Wrong map value");
deba@740
   679
deba@740
   680
    n = 0;
deba@740
   681
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@740
   682
        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
deba@740
   683
        ++n;
deba@740
   684
    }
deba@740
   685
    check(n == num - 3, "Wrong number");
deba@740
   686
    check(map1.trueNum() == num - 3, "Wrong number");
deba@740
   687
deba@740
   688
    n = 0;
deba@740
   689
    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
deba@740
   690
        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
deba@740
   691
        ++n;
deba@740
   692
    }
deba@740
   693
    check(n == 3, "Wrong number");
deba@740
   694
    check(map1.falseNum() == 3, "Wrong number");
deba@740
   695
  }
deba@740
   696
deba@740
   697
  // Iterable int map
deba@740
   698
  {
deba@740
   699
    typedef SmartGraph Graph;
deba@740
   700
    typedef SmartGraph::Node Item;
deba@740
   701
    typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
deba@740
   702
kpeter@741
   703
    checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
deba@740
   704
deba@740
   705
    const int num = 10;
deba@740
   706
    Graph g;
deba@740
   707
    std::vector<Item> items;
deba@740
   708
    for (int i = 0; i < num; ++i) {
deba@740
   709
      items.push_back(g.addNode());
deba@740
   710
    }
deba@740
   711
deba@740
   712
    Iim map1(g);
deba@740
   713
    check(map1.size() == 0, "Wrong size");
deba@740
   714
deba@740
   715
    for (int i = 0; i < num; ++i) {
deba@740
   716
      map1[items[i]] = i;
deba@740
   717
    }
deba@740
   718
    check(map1.size() == num, "Wrong size");
deba@740
   719
deba@740
   720
    for (int i = 0; i < num; ++i) {
deba@740
   721
      Iim::ItemIt it(map1, i);
deba@740
   722
      check(static_cast<Item>(it) == items[i], "Wrong value");
deba@740
   723
      ++it;
deba@740
   724
      check(static_cast<Item>(it) == INVALID, "Wrong value");
deba@740
   725
    }
deba@740
   726
deba@740
   727
    for (int i = 0; i < num; ++i) {
deba@740
   728
      map1[items[i]] = i % 2;
deba@740
   729
    }
deba@740
   730
    check(map1.size() == 2, "Wrong size");
deba@740
   731
deba@740
   732
    int n = 0;
deba@740
   733
    for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
kpeter@741
   734
      check(map1[static_cast<Item>(it)] == 0, "Wrong value");
deba@740
   735
      ++n;
deba@740
   736
    }
deba@740
   737
    check(n == (num + 1) / 2, "Wrong number");
deba@740
   738
deba@740
   739
    for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
kpeter@741
   740
      check(map1[static_cast<Item>(it)] == 1, "Wrong value");
deba@740
   741
      ++n;
deba@740
   742
    }
deba@740
   743
    check(n == num, "Wrong number");
deba@740
   744
deba@740
   745
  }
deba@740
   746
deba@740
   747
  // Iterable value map
deba@740
   748
  {
deba@740
   749
    typedef SmartGraph Graph;
deba@740
   750
    typedef SmartGraph::Node Item;
deba@740
   751
    typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
deba@740
   752
deba@740
   753
    checkConcept<ReadWriteMap<Item, double>, Ivm>();
deba@740
   754
deba@740
   755
    const int num = 10;
deba@740
   756
    Graph g;
deba@740
   757
    std::vector<Item> items;
deba@740
   758
    for (int i = 0; i < num; ++i) {
deba@740
   759
      items.push_back(g.addNode());
deba@740
   760
    }
deba@740
   761
deba@740
   762
    Ivm map1(g, 0.0);
deba@740
   763
    check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
deba@740
   764
    check(*map1.beginValue() == 0.0, "Wrong value");
deba@740
   765
deba@740
   766
    for (int i = 0; i < num; ++i) {
deba@740
   767
      map1.set(items[i], static_cast<double>(i));
deba@740
   768
    }
deba@740
   769
    check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
deba@740
   770
deba@740
   771
    for (int i = 0; i < num; ++i) {
deba@740
   772
      Ivm::ItemIt it(map1, static_cast<double>(i));
deba@740
   773
      check(static_cast<Item>(it) == items[i], "Wrong value");
deba@740
   774
      ++it;
deba@740
   775
      check(static_cast<Item>(it) == INVALID, "Wrong value");
deba@740
   776
    }
deba@740
   777
kpeter@771
   778
    for (Ivm::ValueIt vit = map1.beginValue();
deba@740
   779
         vit != map1.endValue(); ++vit) {
deba@740
   780
      check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
kpeter@771
   781
            "Wrong ValueIt");
deba@740
   782
    }
deba@740
   783
deba@740
   784
    for (int i = 0; i < num; ++i) {
deba@740
   785
      map1.set(items[i], static_cast<double>(i % 2));
deba@740
   786
    }
deba@740
   787
    check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
deba@740
   788
deba@740
   789
    int n = 0;
deba@740
   790
    for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
kpeter@741
   791
      check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
deba@740
   792
      ++n;
deba@740
   793
    }
deba@740
   794
    check(n == (num + 1) / 2, "Wrong number");
deba@740
   795
deba@740
   796
    for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
kpeter@741
   797
      check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
deba@740
   798
      ++n;
deba@740
   799
    }
deba@740
   800
    check(n == num, "Wrong number");
deba@740
   801
deba@740
   802
  }
alpar@25
   803
  return 0;
alpar@25
   804
}