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