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