test/maps_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 29 Jul 2020 14:56:10 +0200
changeset 1433 a278d16bd2d0
parent 1337 4add05447ca0
permissions -rw-r--r--
Fix clang compilation issue (#634)
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@1270
     5
 * Copyright (C) 2003-2013
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>
kpeter@836
    29
#include <algorithm>
alpar@25
    30
alpar@25
    31
#include "test_tools.h"
alpar@25
    32
alpar@25
    33
using namespace lemon;
alpar@25
    34
using namespace lemon::concepts;
alpar@25
    35
alpar@25
    36
struct A {};
alpar@25
    37
inline bool operator<(A, A) { return true; }
alpar@25
    38
struct B {};
alpar@25
    39
kpeter@94
    40
class C {
kpeter@836
    41
  int _x;
kpeter@94
    42
public:
kpeter@836
    43
  C(int x) : _x(x) {}
kpeter@836
    44
  int get() const { return _x; }
kpeter@836
    45
};
kpeter@836
    46
inline bool operator<(C c1, C c2) { return c1.get() < c2.get(); }
kpeter@836
    47
inline bool operator==(C c1, C c2) { return c1.get() == c2.get(); }
kpeter@836
    48
kpeter@836
    49
C createC(int x) { return C(x); }
kpeter@836
    50
kpeter@836
    51
template <typename T>
kpeter@836
    52
class Less {
kpeter@836
    53
  T _t;
kpeter@836
    54
public:
kpeter@836
    55
  Less(T t): _t(t) {}
kpeter@836
    56
  bool operator()(const T& t) const { return t < _t; }
kpeter@94
    57
};
kpeter@94
    58
alpar@25
    59
class F {
alpar@25
    60
public:
alpar@25
    61
  typedef A argument_type;
alpar@25
    62
  typedef B result_type;
alpar@25
    63
alpar@1432
    64
  F() {};
alpar@1432
    65
  F(const F&) {};
alpar@1432
    66
kpeter@80
    67
  B operator()(const A&) const { return B(); }
kpeter@80
    68
private:
kpeter@80
    69
  F& operator=(const F&);
alpar@25
    70
};
alpar@25
    71
kpeter@80
    72
int func(A) { return 3; }
alpar@25
    73
kpeter@80
    74
int binc(int a, B) { return a+1; }
alpar@25
    75
kpeter@836
    76
template <typename T>
kpeter@836
    77
class Sum {
kpeter@836
    78
  T& _sum;
kpeter@836
    79
public:
kpeter@836
    80
  Sum(T& sum) : _sum(sum) {}
kpeter@836
    81
  void operator()(const T& t) { _sum += t; }
kpeter@836
    82
};
kpeter@836
    83
kpeter@80
    84
typedef ReadMap<A, double> DoubleMap;
kpeter@80
    85
typedef ReadWriteMap<A, double> DoubleWriteMap;
kpeter@80
    86
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
alpar@25
    87
kpeter@80
    88
typedef ReadMap<A, bool> BoolMap;
alpar@25
    89
typedef ReadWriteMap<A, bool> BoolWriteMap;
kpeter@80
    90
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
alpar@25
    91
alpar@25
    92
int main()
kpeter@80
    93
{
kpeter@80
    94
  // Map concepts
alpar@25
    95
  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
kpeter@94
    96
  checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
alpar@25
    97
  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
kpeter@94
    98
  checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
alpar@25
    99
  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
kpeter@94
   100
  checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
alpar@25
   101
  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
kpeter@94
   102
  checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
alpar@25
   103
kpeter@80
   104
  // NullMap
kpeter@80
   105
  {
kpeter@80
   106
    checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
kpeter@80
   107
    NullMap<A,B> map1;
kpeter@80
   108
    NullMap<A,B> map2 = map1;
alpar@1257
   109
    ::lemon::ignore_unused_variable_warning(map2);
kpeter@80
   110
    map1 = nullMap<A,B>();
kpeter@80
   111
  }
kpeter@80
   112
kpeter@80
   113
  // ConstMap
kpeter@80
   114
  {
kpeter@80
   115
    checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
kpeter@123
   116
    checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
kpeter@80
   117
    ConstMap<A,B> map1;
deba@136
   118
    ConstMap<A,B> map2 = B();
kpeter@80
   119
    ConstMap<A,B> map3 = map1;
alpar@1257
   120
    ::lemon::ignore_unused_variable_warning(map2,map3);
alpar@1157
   121
kpeter@80
   122
    map1 = constMap<A>(B());
kpeter@123
   123
    map1 = constMap<A,B>();
kpeter@80
   124
    map1.setAll(B());
kpeter@123
   125
    ConstMap<A,C> map4(C(1));
kpeter@123
   126
    ConstMap<A,C> map5 = map4;
alpar@1257
   127
    ::lemon::ignore_unused_variable_warning(map5);
alpar@1157
   128
kpeter@123
   129
    map4 = constMap<A>(C(2));
kpeter@123
   130
    map4.setAll(C(3));
kpeter@82
   131
kpeter@80
   132
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
kpeter@80
   133
    check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
kpeter@80
   134
kpeter@80
   135
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
kpeter@123
   136
    ConstMap<A,Const<int,10> > map6;
kpeter@123
   137
    ConstMap<A,Const<int,10> > map7 = map6;
kpeter@123
   138
    map6 = constMap<A,int,10>();
kpeter@123
   139
    map7 = constMap<A,Const<int,10> >();
alpar@210
   140
    check(map6[A()] == 10 && map7[A()] == 10,
alpar@210
   141
          "Something is wrong with ConstMap");
kpeter@80
   142
  }
kpeter@80
   143
kpeter@80
   144
  // IdentityMap
kpeter@80
   145
  {
kpeter@80
   146
    checkConcept<ReadMap<A,A>, IdentityMap<A> >();
kpeter@80
   147
    IdentityMap<A> map1;
kpeter@80
   148
    IdentityMap<A> map2 = map1;
alpar@1257
   149
    ::lemon::ignore_unused_variable_warning(map2);
alpar@1157
   150
kpeter@80
   151
    map1 = identityMap<A>();
kpeter@82
   152
kpeter@80
   153
    checkConcept<ReadMap<double,double>, IdentityMap<double> >();
alpar@210
   154
    check(identityMap<double>()[1.0] == 1.0 &&
alpar@210
   155
          identityMap<double>()[3.14] == 3.14,
kpeter@80
   156
          "Something is wrong with IdentityMap");
kpeter@80
   157
  }
kpeter@80
   158
kpeter@80
   159
  // RangeMap
kpeter@80
   160
  {
kpeter@80
   161
    checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >();
kpeter@80
   162
    RangeMap<B> map1;
kpeter@80
   163
    RangeMap<B> map2(10);
kpeter@80
   164
    RangeMap<B> map3(10,B());
kpeter@80
   165
    RangeMap<B> map4 = map1;
kpeter@80
   166
    RangeMap<B> map5 = rangeMap<B>();
kpeter@80
   167
    RangeMap<B> map6 = rangeMap<B>(10);
kpeter@80
   168
    RangeMap<B> map7 = rangeMap(10,B());
kpeter@80
   169
kpeter@80
   170
    checkConcept< ReferenceMap<int, double, double&, const double&>,
kpeter@80
   171
                  RangeMap<double> >();
kpeter@80
   172
    std::vector<double> v(10, 0);
kpeter@80
   173
    v[5] = 100;
kpeter@80
   174
    RangeMap<double> map8(v);
kpeter@80
   175
    RangeMap<double> map9 = rangeMap(v);
kpeter@80
   176
    check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100,
kpeter@80
   177
          "Something is wrong with RangeMap");
kpeter@80
   178
  }
kpeter@80
   179
kpeter@80
   180
  // SparseMap
kpeter@80
   181
  {
kpeter@80
   182
    checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >();
kpeter@80
   183
    SparseMap<A,B> map1;
deba@136
   184
    SparseMap<A,B> map2 = B();
kpeter@80
   185
    SparseMap<A,B> map3 = sparseMap<A,B>();
kpeter@80
   186
    SparseMap<A,B> map4 = sparseMap<A>(B());
kpeter@80
   187
kpeter@80
   188
    checkConcept< ReferenceMap<double, int, int&, const int&>,
kpeter@80
   189
                  SparseMap<double, int> >();
kpeter@80
   190
    std::map<double, int> m;
kpeter@80
   191
    SparseMap<double, int> map5(m);
kpeter@80
   192
    SparseMap<double, int> map6(m,10);
kpeter@80
   193
    SparseMap<double, int> map7 = sparseMap(m);
kpeter@80
   194
    SparseMap<double, int> map8 = sparseMap(m,10);
kpeter@80
   195
alpar@210
   196
    check(map5[1.0] == 0 && map5[3.14] == 0 &&
alpar@210
   197
          map6[1.0] == 10 && map6[3.14] == 10,
kpeter@80
   198
          "Something is wrong with SparseMap");
kpeter@80
   199
    map5[1.0] = map6[3.14] = 100;
alpar@210
   200
    check(map5[1.0] == 100 && map5[3.14] == 0 &&
alpar@210
   201
          map6[1.0] == 10 && map6[3.14] == 100,
kpeter@80
   202
          "Something is wrong with SparseMap");
kpeter@80
   203
  }
kpeter@80
   204
kpeter@80
   205
  // ComposeMap
kpeter@80
   206
  {
kpeter@80
   207
    typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
kpeter@80
   208
    checkConcept<ReadMap<B,double>, CompMap>();
alpar@554
   209
    CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
alpar@1257
   210
    ::lemon::ignore_unused_variable_warning(map1);
kpeter@80
   211
    CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
alpar@1257
   212
    ::lemon::ignore_unused_variable_warning(map2);
kpeter@82
   213
kpeter@80
   214
    SparseMap<double, bool> m1(false); m1[3.14] = true;
kpeter@80
   215
    RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
alpar@210
   216
    check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
alpar@210
   217
          "Something is wrong with ComposeMap")
kpeter@80
   218
  }
kpeter@80
   219
kpeter@80
   220
  // CombineMap
kpeter@80
   221
  {
kpeter@80
   222
    typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
kpeter@80
   223
    checkConcept<ReadMap<A,double>, CombMap>();
alpar@554
   224
    CombMap map1 = CombMap(DoubleMap(), DoubleMap());
alpar@1257
   225
    ::lemon::ignore_unused_variable_warning(map1);
kpeter@80
   226
    CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
alpar@1257
   227
    ::lemon::ignore_unused_variable_warning(map2);
kpeter@80
   228
kpeter@80
   229
    check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
kpeter@80
   230
          "Something is wrong with CombineMap");
kpeter@80
   231
  }
kpeter@80
   232
kpeter@80
   233
  // FunctorToMap, MapToFunctor
kpeter@80
   234
  {
kpeter@80
   235
    checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
kpeter@80
   236
    checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
kpeter@80
   237
    FunctorToMap<F> map1;
alpar@554
   238
    FunctorToMap<F> map2 = FunctorToMap<F>(F());
alpar@1257
   239
    ::lemon::ignore_unused_variable_warning(map2);
alpar@1157
   240
kpeter@80
   241
    B b = functorToMap(F())[A()];
alpar@1257
   242
    ::lemon::ignore_unused_variable_warning(b);
kpeter@80
   243
kpeter@80
   244
    checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
alpar@1157
   245
    MapToFunctor<ReadMap<A,B> > map =
alpar@1157
   246
      MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
alpar@1257
   247
    ::lemon::ignore_unused_variable_warning(map);
kpeter@80
   248
alpar@210
   249
    check(functorToMap(&func)[A()] == 3,
alpar@210
   250
          "Something is wrong with FunctorToMap");
alpar@210
   251
    check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
alpar@210
   252
          "Something is wrong with MapToFunctor");
alpar@210
   253
    check(mapToFunctor(functorToMap(&func))(A()) == 3 &&
alpar@210
   254
          mapToFunctor(functorToMap(&func))[A()] == 3,
kpeter@80
   255
          "Something is wrong with FunctorToMap or MapToFunctor");
kpeter@80
   256
    check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2,
kpeter@80
   257
          "Something is wrong with FunctorToMap or MapToFunctor");
kpeter@80
   258
  }
kpeter@80
   259
kpeter@80
   260
  // ConvertMap
kpeter@80
   261
  {
alpar@210
   262
    checkConcept<ReadMap<double,double>,
alpar@210
   263
      ConvertMap<ReadMap<double, int>, double> >();
kpeter@80
   264
    ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
alpar@1257
   265
    ::lemon::ignore_unused_variable_warning(map1);
kpeter@80
   266
    ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
alpar@1257
   267
    ::lemon::ignore_unused_variable_warning(map2);
alpar@1157
   268
kpeter@80
   269
  }
kpeter@80
   270
kpeter@80
   271
  // ForkMap
kpeter@80
   272
  {
kpeter@80
   273
    checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
kpeter@82
   274
kpeter@80
   275
    typedef RangeMap<double> RM;
kpeter@80
   276
    typedef SparseMap<int, double> SM;
kpeter@80
   277
    RM m1(10, -1);
kpeter@80
   278
    SM m2(-1);
kpeter@80
   279
    checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
kpeter@80
   280
    checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >();
kpeter@80
   281
    ForkMap<RM, SM> map1(m1,m2);
kpeter@80
   282
    ForkMap<SM, RM> map2 = forkMap(m2,m1);
kpeter@80
   283
    map2.set(5, 10);
alpar@210
   284
    check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 &&
alpar@210
   285
          m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
kpeter@80
   286
          "Something is wrong with ForkMap");
kpeter@80
   287
  }
kpeter@82
   288
kpeter@80
   289
  // Arithmetic maps:
kpeter@80
   290
  // - AddMap, SubMap, MulMap, DivMap
kpeter@80
   291
  // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
kpeter@80
   292
  // - NegMap, NegWriteMap, AbsMap
kpeter@80
   293
  {
kpeter@80
   294
    checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
kpeter@80
   295
    checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
kpeter@80
   296
    checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
kpeter@80
   297
    checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
kpeter@82
   298
kpeter@80
   299
    ConstMap<int, double> c1(1.0), c2(3.14);
kpeter@80
   300
    IdentityMap<int> im;
kpeter@80
   301
    ConvertMap<IdentityMap<int>, double> id(im);
alpar@210
   302
    check(addMap(c1,id)[0] == 1.0  && addMap(c1,id)[10] == 11.0,
alpar@210
   303
          "Something is wrong with AddMap");
alpar@210
   304
    check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,
alpar@210
   305
          "Something is wrong with SubMap");
alpar@210
   306
    check(mulMap(id,c2)[0] == 0    && mulMap(id,c2)[2]  == 6.28,
alpar@210
   307
          "Something is wrong with MulMap");
alpar@210
   308
    check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2]  == 1.57,
alpar@210
   309
          "Something is wrong with DivMap");
kpeter@82
   310
kpeter@80
   311
    checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
kpeter@80
   312
    checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
kpeter@80
   313
    checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
kpeter@80
   314
    checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
kpeter@80
   315
    checkConcept<DoubleMap, NegMap<DoubleMap> >();
kpeter@80
   316
    checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >();
kpeter@80
   317
    checkConcept<DoubleMap, AbsMap<DoubleMap> >();
alpar@25
   318
kpeter@80
   319
    check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0,
kpeter@80
   320
          "Something is wrong with ShiftMap");
alpar@210
   321
    check(shiftWriteMap(id, 2.0)[1] == 3.0 &&
alpar@210
   322
          shiftWriteMap(id, 2.0)[10] == 12.0,
kpeter@80
   323
          "Something is wrong with ShiftWriteMap");
kpeter@80
   324
    check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0,
kpeter@80
   325
          "Something is wrong with ScaleMap");
alpar@210
   326
    check(scaleWriteMap(id, 2.0)[1] == 2.0 &&
alpar@210
   327
          scaleWriteMap(id, 2.0)[10] == 20.0,
kpeter@80
   328
          "Something is wrong with ScaleWriteMap");
kpeter@80
   329
    check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0,
kpeter@80
   330
          "Something is wrong with NegMap");
kpeter@80
   331
    check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
kpeter@80
   332
          "Something is wrong with NegWriteMap");
kpeter@80
   333
    check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
kpeter@80
   334
          "Something is wrong with AbsMap");
kpeter@80
   335
  }
kpeter@82
   336
kpeter@82
   337
  // Logical maps:
kpeter@82
   338
  // - TrueMap, FalseMap
kpeter@82
   339
  // - AndMap, OrMap
kpeter@82
   340
  // - NotMap, NotWriteMap
kpeter@82
   341
  // - EqualMap, LessMap
kpeter@80
   342
  {
kpeter@82
   343
    checkConcept<BoolMap, TrueMap<A> >();
kpeter@82
   344
    checkConcept<BoolMap, FalseMap<A> >();
kpeter@82
   345
    checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
kpeter@82
   346
    checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
kpeter@80
   347
    checkConcept<BoolMap, NotMap<BoolMap> >();
kpeter@80
   348
    checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
kpeter@82
   349
    checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
kpeter@82
   350
    checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
kpeter@82
   351
kpeter@82
   352
    TrueMap<int> tm;
kpeter@82
   353
    FalseMap<int> fm;
kpeter@80
   354
    RangeMap<bool> rm(2);
kpeter@80
   355
    rm[0] = true; rm[1] = false;
alpar@210
   356
    check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] &&
alpar@210
   357
          !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
kpeter@82
   358
          "Something is wrong with AndMap");
alpar@210
   359
    check(orMap(tm,rm)[0] && orMap(tm,rm)[1] &&
alpar@210
   360
          orMap(fm,rm)[0] && !orMap(fm,rm)[1],
kpeter@82
   361
          "Something is wrong with OrMap");
alpar@210
   362
    check(!notMap(rm)[0] && notMap(rm)[1],
alpar@210
   363
          "Something is wrong with NotMap");
alpar@210
   364
    check(!notWriteMap(rm)[0] && notWriteMap(rm)[1],
alpar@210
   365
          "Something is wrong with NotWriteMap");
kpeter@82
   366
kpeter@82
   367
    ConstMap<int, double> cm(2.0);
kpeter@82
   368
    IdentityMap<int> im;
kpeter@82
   369
    ConvertMap<IdentityMap<int>, double> id(im);
kpeter@82
   370
    check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
kpeter@82
   371
          "Something is wrong with LessMap");
kpeter@82
   372
    check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
kpeter@82
   373
          "Something is wrong with EqualMap");
kpeter@80
   374
  }
alpar@209
   375
kpeter@167
   376
  // LoggerBoolMap
kpeter@159
   377
  {
kpeter@159
   378
    typedef std::vector<int> vec;
kpeter@767
   379
    checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
kpeter@767
   380
    checkConcept<WriteMap<int, bool>,
kpeter@767
   381
                 LoggerBoolMap<std::back_insert_iterator<vec> > >();
kpeter@767
   382
kpeter@159
   383
    vec v1;
kpeter@159
   384
    vec v2(10);
alpar@210
   385
    LoggerBoolMap<std::back_insert_iterator<vec> >
alpar@210
   386
      map1(std::back_inserter(v1));
kpeter@167
   387
    LoggerBoolMap<vec::iterator> map2(v2.begin());
kpeter@159
   388
    map1.set(10, false);
kpeter@159
   389
    map1.set(20, true);   map2.set(20, true);
kpeter@159
   390
    map1.set(30, false);  map2.set(40, false);
kpeter@159
   391
    map1.set(50, true);   map2.set(50, true);
kpeter@159
   392
    map1.set(60, true);   map2.set(60, true);
kpeter@159
   393
    check(v1.size() == 3 && v2.size() == 10 &&
alpar@210
   394
          v1[0]==20 && v1[1]==50 && v1[2]==60 &&
alpar@210
   395
          v2[0]==20 && v2[1]==50 && v2[2]==60,
kpeter@167
   396
          "Something is wrong with LoggerBoolMap");
alpar@209
   397
kpeter@159
   398
    int i = 0;
kpeter@167
   399
    for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
kpeter@159
   400
          it != map2.end(); ++it )
kpeter@167
   401
      check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
alpar@956
   402
kpeter@770
   403
    typedef ListDigraph Graph;
kpeter@770
   404
    DIGRAPH_TYPEDEFS(Graph);
kpeter@770
   405
    Graph gr;
kpeter@770
   406
kpeter@770
   407
    Node n0 = gr.addNode();
kpeter@770
   408
    Node n1 = gr.addNode();
kpeter@770
   409
    Node n2 = gr.addNode();
kpeter@770
   410
    Node n3 = gr.addNode();
alpar@956
   411
kpeter@770
   412
    gr.addArc(n3, n0);
kpeter@770
   413
    gr.addArc(n3, n2);
kpeter@770
   414
    gr.addArc(n0, n2);
kpeter@770
   415
    gr.addArc(n2, n1);
kpeter@770
   416
    gr.addArc(n0, n1);
alpar@956
   417
kpeter@770
   418
    {
kpeter@770
   419
      std::vector<Node> v;
kpeter@770
   420
      dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
kpeter@770
   421
kpeter@770
   422
      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
kpeter@770
   423
            "Something is wrong with LoggerBoolMap");
kpeter@770
   424
    }
kpeter@770
   425
    {
kpeter@770
   426
      std::vector<Node> v(countNodes(gr));
kpeter@770
   427
      dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
alpar@956
   428
kpeter@770
   429
      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
kpeter@770
   430
            "Something is wrong with LoggerBoolMap");
kpeter@770
   431
    }
kpeter@159
   432
  }
alpar@956
   433
kpeter@767
   434
  // IdMap, RangeIdMap
kpeter@767
   435
  {
kpeter@767
   436
    typedef ListDigraph Graph;
kpeter@767
   437
    DIGRAPH_TYPEDEFS(Graph);
kpeter@767
   438
kpeter@767
   439
    checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
kpeter@767
   440
    checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
kpeter@767
   441
    checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
kpeter@767
   442
    checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
alpar@956
   443
kpeter@767
   444
    Graph gr;
kpeter@767
   445
    IdMap<Graph, Node> nmap(gr);
kpeter@767
   446
    IdMap<Graph, Arc> amap(gr);
kpeter@767
   447
    RangeIdMap<Graph, Node> nrmap(gr);
kpeter@767
   448
    RangeIdMap<Graph, Arc> armap(gr);
alpar@956
   449
kpeter@767
   450
    Node n0 = gr.addNode();
kpeter@767
   451
    Node n1 = gr.addNode();
kpeter@767
   452
    Node n2 = gr.addNode();
alpar@956
   453
kpeter@767
   454
    Arc a0 = gr.addArc(n0, n1);
kpeter@767
   455
    Arc a1 = gr.addArc(n0, n2);
kpeter@767
   456
    Arc a2 = gr.addArc(n2, n1);
kpeter@767
   457
    Arc a3 = gr.addArc(n2, n0);
alpar@956
   458
kpeter@767
   459
    check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
kpeter@767
   460
    check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
kpeter@767
   461
    check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
kpeter@767
   462
kpeter@767
   463
    check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
kpeter@767
   464
    check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
kpeter@767
   465
    check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
kpeter@767
   466
    check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
kpeter@767
   467
kpeter@767
   468
    check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
kpeter@767
   469
    check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
alpar@956
   470
kpeter@767
   471
    check(nrmap.size() == 3 && armap.size() == 4,
kpeter@767
   472
          "Wrong RangeIdMap::size()");
kpeter@767
   473
kpeter@767
   474
    check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
kpeter@767
   475
    check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
kpeter@767
   476
    check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
alpar@956
   477
kpeter@767
   478
    check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
kpeter@767
   479
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
kpeter@767
   480
    check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
kpeter@767
   481
    check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
kpeter@767
   482
kpeter@767
   483
    check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
kpeter@767
   484
    check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
alpar@956
   485
kpeter@767
   486
    gr.erase(n1);
alpar@956
   487
kpeter@767
   488
    if (nrmap[n0] == 1) nrmap.swap(n0, n2);
kpeter@767
   489
    nrmap.swap(n2, n0);
kpeter@767
   490
    if (armap[a1] == 1) armap.swap(a1, a3);
kpeter@767
   491
    armap.swap(a3, a1);
alpar@956
   492
kpeter@767
   493
    check(nrmap.size() == 2 && armap.size() == 2,
kpeter@767
   494
          "Wrong RangeIdMap::size()");
kpeter@767
   495
kpeter@767
   496
    check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
kpeter@767
   497
    check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
alpar@956
   498
kpeter@767
   499
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
kpeter@767
   500
    check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
kpeter@767
   501
kpeter@767
   502
    check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
kpeter@767
   503
    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
kpeter@767
   504
  }
alpar@956
   505
kpeter@770
   506
  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
kpeter@770
   507
  {
kpeter@770
   508
    typedef ListGraph Graph;
kpeter@770
   509
    GRAPH_TYPEDEFS(Graph);
alpar@956
   510
kpeter@770
   511
    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
kpeter@770
   512
    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
kpeter@770
   513
    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
kpeter@770
   514
    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
kpeter@770
   515
    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
kpeter@770
   516
    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
kpeter@770
   517
kpeter@770
   518
    Graph gr;
kpeter@770
   519
    Node n0 = gr.addNode();
kpeter@770
   520
    Node n1 = gr.addNode();
kpeter@770
   521
    Node n2 = gr.addNode();
alpar@956
   522
kpeter@770
   523
    gr.addEdge(n0,n1);
kpeter@770
   524
    gr.addEdge(n1,n2);
kpeter@770
   525
    gr.addEdge(n0,n2);
kpeter@770
   526
    gr.addEdge(n2,n1);
kpeter@770
   527
    gr.addEdge(n1,n2);
kpeter@770
   528
    gr.addEdge(n0,n1);
alpar@956
   529
kpeter@770
   530
    for (EdgeIt e(gr); e != INVALID; ++e) {
kpeter@770
   531
      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
kpeter@770
   532
      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
kpeter@770
   533
    }
alpar@956
   534
kpeter@836
   535
    check(mapCompare(gr,
kpeter@836
   536
          sourceMap(orienter(gr, constMap<Edge, bool>(true))),
kpeter@836
   537
          targetMap(orienter(gr, constMap<Edge, bool>(false)))),
kpeter@836
   538
          "Wrong SourceMap or TargetMap");
kpeter@770
   539
kpeter@770
   540
    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
alpar@1235
   541
    ConstMap<Edge, bool> true_edge_map(true);
alpar@1235
   542
    Digraph dgr(gr, true_edge_map);
kpeter@770
   543
    OutDegMap<Digraph> odm(dgr);
kpeter@770
   544
    InDegMap<Digraph> idm(dgr);
alpar@956
   545
kpeter@770
   546
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
kpeter@770
   547
    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
alpar@956
   548
kpeter@770
   549
    gr.addEdge(n2, n0);
kpeter@770
   550
kpeter@770
   551
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
kpeter@770
   552
    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
kpeter@770
   553
  }
alpar@956
   554
kpeter@731
   555
  // CrossRefMap
kpeter@731
   556
  {
kpeter@731
   557
    typedef ListDigraph Graph;
kpeter@731
   558
    DIGRAPH_TYPEDEFS(Graph);
kpeter@731
   559
kpeter@731
   560
    checkConcept<ReadWriteMap<Node, int>,
kpeter@731
   561
                 CrossRefMap<Graph, Node, int> >();
kpeter@767
   562
    checkConcept<ReadWriteMap<Node, bool>,
kpeter@767
   563
                 CrossRefMap<Graph, Node, bool> >();
kpeter@767
   564
    checkConcept<ReadWriteMap<Node, double>,
kpeter@767
   565
                 CrossRefMap<Graph, Node, double> >();
alpar@956
   566
kpeter@731
   567
    Graph gr;
kpeter@731
   568
    typedef CrossRefMap<Graph, Node, char> CRMap;
kpeter@731
   569
    CRMap map(gr);
alpar@956
   570
kpeter@731
   571
    Node n0 = gr.addNode();
kpeter@731
   572
    Node n1 = gr.addNode();
kpeter@731
   573
    Node n2 = gr.addNode();
alpar@956
   574
kpeter@731
   575
    map.set(n0, 'A');
kpeter@731
   576
    map.set(n1, 'B');
kpeter@731
   577
    map.set(n2, 'C');
alpar@956
   578
kpeter@767
   579
    check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
kpeter@767
   580
          "Wrong CrossRefMap");
kpeter@767
   581
    check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
kpeter@767
   582
          "Wrong CrossRefMap");
kpeter@767
   583
    check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
kpeter@767
   584
          "Wrong CrossRefMap");
kpeter@767
   585
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
kpeter@767
   586
          "Wrong CrossRefMap::count()");
alpar@956
   587
kpeter@771
   588
    CRMap::ValueIt it = map.beginValue();
kpeter@767
   589
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@767
   590
          it == map.endValue(), "Wrong value iterator");
alpar@956
   591
kpeter@731
   592
    map.set(n2, 'A');
kpeter@767
   593
kpeter@767
   594
    check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
kpeter@767
   595
          "Wrong CrossRefMap");
kpeter@767
   596
    check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
kpeter@767
   597
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@767
   598
    check(map('C') == INVALID && map.inverse()['C'] == INVALID,
kpeter@767
   599
          "Wrong CrossRefMap");
kpeter@767
   600
    check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
kpeter@767
   601
          "Wrong CrossRefMap::count()");
kpeter@767
   602
kpeter@767
   603
    it = map.beginValue();
kpeter@767
   604
    check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
kpeter@767
   605
          it == map.endValue(), "Wrong value iterator");
kpeter@767
   606
kpeter@731
   607
    map.set(n0, 'C');
kpeter@731
   608
kpeter@731
   609
    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
kpeter@731
   610
          "Wrong CrossRefMap");
kpeter@731
   611
    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
kpeter@731
   612
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@731
   613
    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
kpeter@767
   614
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
kpeter@767
   615
          "Wrong CrossRefMap::count()");
kpeter@731
   616
kpeter@767
   617
    it = map.beginValue();
kpeter@731
   618
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@731
   619
          it == map.endValue(), "Wrong value iterator");
alpar@554
   620
  }
alpar@554
   621
kpeter@731
   622
  // CrossRefMap
kpeter@731
   623
  {
alpar@742
   624
    typedef SmartDigraph Graph;
kpeter@731
   625
    DIGRAPH_TYPEDEFS(Graph);
kpeter@731
   626
kpeter@731
   627
    checkConcept<ReadWriteMap<Node, int>,
kpeter@731
   628
                 CrossRefMap<Graph, Node, int> >();
alpar@956
   629
kpeter@731
   630
    Graph gr;
kpeter@731
   631
    typedef CrossRefMap<Graph, Node, char> CRMap;
kpeter@731
   632
    typedef CRMap::ValueIterator ValueIt;
kpeter@731
   633
    CRMap map(gr);
alpar@956
   634
kpeter@731
   635
    Node n0 = gr.addNode();
kpeter@731
   636
    Node n1 = gr.addNode();
kpeter@731
   637
    Node n2 = gr.addNode();
alpar@956
   638
kpeter@731
   639
    map.set(n0, 'A');
kpeter@731
   640
    map.set(n1, 'B');
kpeter@731
   641
    map.set(n2, 'C');
kpeter@731
   642
    map.set(n2, 'A');
kpeter@731
   643
    map.set(n0, 'C');
kpeter@731
   644
kpeter@731
   645
    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
kpeter@731
   646
          "Wrong CrossRefMap");
kpeter@731
   647
    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
kpeter@731
   648
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
kpeter@731
   649
    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
kpeter@731
   650
kpeter@731
   651
    ValueIt it = map.beginValue();
kpeter@731
   652
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
kpeter@731
   653
          it == map.endValue(), "Wrong value iterator");
kpeter@731
   654
  }
alpar@25
   655
deba@740
   656
  // Iterable bool map
deba@740
   657
  {
deba@740
   658
    typedef SmartGraph Graph;
deba@740
   659
    typedef SmartGraph::Node Item;
deba@740
   660
deba@740
   661
    typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
kpeter@741
   662
    checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
deba@740
   663
deba@740
   664
    const int num = 10;
deba@740
   665
    Graph g;
deba@1057
   666
    Ibm map0(g, true);
deba@740
   667
    std::vector<Item> items;
deba@740
   668
    for (int i = 0; i < num; ++i) {
deba@740
   669
      items.push_back(g.addNode());
deba@740
   670
    }
deba@740
   671
deba@740
   672
    Ibm map1(g, true);
deba@740
   673
    int n = 0;
deba@740
   674
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@740
   675
      check(map1[static_cast<Item>(it)], "Wrong TrueIt");
deba@740
   676
      ++n;
deba@740
   677
    }
deba@740
   678
    check(n == num, "Wrong number");
deba@740
   679
deba@740
   680
    n = 0;
deba@740
   681
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
deba@740
   682
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
deba@740
   683
        ++n;
deba@740
   684
    }
deba@740
   685
    check(n == num, "Wrong number");
deba@740
   686
    check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
deba@740
   687
    check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
deba@740
   688
deba@740
   689
    map1[items[5]] = true;
deba@740
   690
deba@740
   691
    n = 0;
deba@740
   692
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
deba@740
   693
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
deba@740
   694
        ++n;
deba@740
   695
    }
deba@740
   696
    check(n == num, "Wrong number");
deba@740
   697
deba@740
   698
    map1[items[num / 2]] = false;
deba@740
   699
    check(map1[items[num / 2]] == false, "Wrong map value");
deba@740
   700
deba@740
   701
    n = 0;
deba@740
   702
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@740
   703
        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
deba@740
   704
        ++n;
deba@740
   705
    }
deba@740
   706
    check(n == num - 1, "Wrong number");
deba@740
   707
deba@740
   708
    n = 0;
deba@740
   709
    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
deba@740
   710
        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
deba@740
   711
        ++n;
deba@740
   712
    }
deba@740
   713
    check(n == 1, "Wrong number");
deba@740
   714
deba@740
   715
    map1[items[0]] = false;
deba@740
   716
    check(map1[items[0]] == false, "Wrong map value");
deba@740
   717
deba@740
   718
    map1[items[num - 1]] = false;
deba@740
   719
    check(map1[items[num - 1]] == false, "Wrong map value");
deba@740
   720
deba@740
   721
    n = 0;
deba@740
   722
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
deba@740
   723
        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
deba@740
   724
        ++n;
deba@740
   725
    }
deba@740
   726
    check(n == num - 3, "Wrong number");
deba@740
   727
    check(map1.trueNum() == num - 3, "Wrong number");
deba@740
   728
deba@740
   729
    n = 0;
deba@740
   730
    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
deba@740
   731
        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
deba@740
   732
        ++n;
deba@740
   733
    }
deba@740
   734
    check(n == 3, "Wrong number");
deba@740
   735
    check(map1.falseNum() == 3, "Wrong number");
alpar@1337
   736
alpar@1337
   737
#ifdef LEMON_CXX11
alpar@1337
   738
    {
alpar@1337
   739
      int c = 0;
alpar@1337
   740
      for(auto v: map1.items(false)) { c++; ::lemon::ignore_unused_variable_warning(v); }
alpar@1337
   741
      check(c == map1.falseNum(), "Wrong number");
alpar@1337
   742
    }
alpar@1337
   743
    {
alpar@1337
   744
      int c = 0;
alpar@1337
   745
      for(auto v: map1.items(true)) { c++; ::lemon::ignore_unused_variable_warning(v); }
alpar@1337
   746
      check(c == map1.trueNum(), "Wrong number");
alpar@1337
   747
    }
alpar@1337
   748
    {
alpar@1337
   749
      int c = 0;
alpar@1337
   750
      for(auto v: map1.falseKeys()) { c++; ::lemon::ignore_unused_variable_warning(v); }
alpar@1337
   751
      check(c == map1.falseNum(), "Wrong number");
alpar@1337
   752
    }
alpar@1337
   753
    {
alpar@1337
   754
      int c = 0;
alpar@1337
   755
      for(auto v: map1.trueKeys()) { c++; ::lemon::ignore_unused_variable_warning(v); }
alpar@1337
   756
      check(c == map1.trueNum(), "Wrong number");
alpar@1337
   757
    }
alpar@1337
   758
#endif
alpar@1337
   759
deba@740
   760
  }
deba@740
   761
deba@740
   762
  // Iterable int map
deba@740
   763
  {
deba@740
   764
    typedef SmartGraph Graph;
deba@740
   765
    typedef SmartGraph::Node Item;
deba@740
   766
    typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
deba@740
   767
kpeter@741
   768
    checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
deba@740
   769
deba@740
   770
    const int num = 10;
deba@740
   771
    Graph g;
deba@1057
   772
    Iim map0(g, 0);
deba@740
   773
    std::vector<Item> items;
deba@740
   774
    for (int i = 0; i < num; ++i) {
deba@740
   775
      items.push_back(g.addNode());
deba@740
   776
    }
deba@740
   777
deba@740
   778
    Iim map1(g);
deba@740
   779
    check(map1.size() == 0, "Wrong size");
deba@740
   780
deba@740
   781
    for (int i = 0; i < num; ++i) {
deba@740
   782
      map1[items[i]] = i;
deba@740
   783
    }
deba@740
   784
    check(map1.size() == num, "Wrong size");
deba@740
   785
deba@740
   786
    for (int i = 0; i < num; ++i) {
deba@740
   787
      Iim::ItemIt it(map1, i);
deba@740
   788
      check(static_cast<Item>(it) == items[i], "Wrong value");
deba@740
   789
      ++it;
deba@740
   790
      check(static_cast<Item>(it) == INVALID, "Wrong value");
deba@740
   791
    }
deba@740
   792
deba@740
   793
    for (int i = 0; i < num; ++i) {
deba@740
   794
      map1[items[i]] = i % 2;
deba@740
   795
    }
deba@740
   796
    check(map1.size() == 2, "Wrong size");
deba@740
   797
deba@740
   798
    int n = 0;
deba@740
   799
    for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
kpeter@741
   800
      check(map1[static_cast<Item>(it)] == 0, "Wrong value");
deba@740
   801
      ++n;
deba@740
   802
    }
deba@740
   803
    check(n == (num + 1) / 2, "Wrong number");
deba@740
   804
deba@740
   805
    for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
kpeter@741
   806
      check(map1[static_cast<Item>(it)] == 1, "Wrong value");
deba@740
   807
      ++n;
deba@740
   808
    }
deba@740
   809
    check(n == num, "Wrong number");
alpar@1337
   810
#ifdef LEMON_CXX11
alpar@1337
   811
    {
alpar@1337
   812
      int c = 0;
alpar@1337
   813
      for(auto v: map1.items(0)) { c++; ::lemon::ignore_unused_variable_warning(v); }
alpar@1337
   814
      check(c == (num + 1) / 2, "Wrong number");
alpar@1337
   815
      for(auto v: map1.items(1)) { c++; ::lemon::ignore_unused_variable_warning(v); }
alpar@1337
   816
      check(c == num, "Wrong number");
alpar@1337
   817
    }
alpar@1337
   818
#endif
deba@740
   819
deba@740
   820
  }
deba@740
   821
deba@740
   822
  // Iterable value map
deba@740
   823
  {
deba@740
   824
    typedef SmartGraph Graph;
deba@740
   825
    typedef SmartGraph::Node Item;
deba@740
   826
    typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
deba@740
   827
deba@740
   828
    checkConcept<ReadWriteMap<Item, double>, Ivm>();
deba@740
   829
deba@740
   830
    const int num = 10;
deba@740
   831
    Graph g;
deba@1057
   832
    Ivm map0(g, 0.0);
deba@740
   833
    std::vector<Item> items;
deba@740
   834
    for (int i = 0; i < num; ++i) {
deba@740
   835
      items.push_back(g.addNode());
deba@740
   836
    }
deba@740
   837
deba@740
   838
    Ivm map1(g, 0.0);
deba@740
   839
    check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
deba@740
   840
    check(*map1.beginValue() == 0.0, "Wrong value");
deba@740
   841
deba@740
   842
    for (int i = 0; i < num; ++i) {
deba@740
   843
      map1.set(items[i], static_cast<double>(i));
deba@740
   844
    }
deba@740
   845
    check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
deba@740
   846
deba@740
   847
    for (int i = 0; i < num; ++i) {
deba@740
   848
      Ivm::ItemIt it(map1, static_cast<double>(i));
deba@740
   849
      check(static_cast<Item>(it) == items[i], "Wrong value");
deba@740
   850
      ++it;
deba@740
   851
      check(static_cast<Item>(it) == INVALID, "Wrong value");
deba@740
   852
    }
deba@740
   853
kpeter@771
   854
    for (Ivm::ValueIt vit = map1.beginValue();
deba@740
   855
         vit != map1.endValue(); ++vit) {
deba@740
   856
      check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
kpeter@771
   857
            "Wrong ValueIt");
deba@740
   858
    }
deba@740
   859
deba@740
   860
    for (int i = 0; i < num; ++i) {
deba@740
   861
      map1.set(items[i], static_cast<double>(i % 2));
deba@740
   862
    }
deba@740
   863
    check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
deba@740
   864
deba@740
   865
    int n = 0;
deba@740
   866
    for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
kpeter@741
   867
      check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
deba@740
   868
      ++n;
deba@740
   869
    }
deba@740
   870
    check(n == (num + 1) / 2, "Wrong number");
deba@740
   871
deba@740
   872
    for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
kpeter@741
   873
      check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
deba@740
   874
      ++n;
deba@740
   875
    }
deba@740
   876
    check(n == num, "Wrong number");
deba@740
   877
alpar@1337
   878
#ifdef LEMON_CXX11
alpar@1337
   879
    {
alpar@1337
   880
      int c = 0;
alpar@1337
   881
      for(auto v: map1.items(0.0)) { c++; ::lemon::ignore_unused_variable_warning(v); }
alpar@1337
   882
      check(c == (num + 1) / 2, "Wrong number");
alpar@1337
   883
      for(auto v: map1.items(1.0)) { c++; ::lemon::ignore_unused_variable_warning(v); }
alpar@1337
   884
      check(c == num, "Wrong number");
alpar@1337
   885
    }
alpar@1337
   886
#endif
alpar@1337
   887
deba@740
   888
  }
alpar@956
   889
kpeter@836
   890
  // Graph map utilities:
kpeter@836
   891
  // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
kpeter@836
   892
  // mapFind(), mapFindIf(), mapCount(), mapCountIf()
kpeter@836
   893
  // mapCopy(), mapCompare(), mapFill()
kpeter@836
   894
  {
kpeter@836
   895
    DIGRAPH_TYPEDEFS(SmartDigraph);
kpeter@836
   896
kpeter@836
   897
    SmartDigraph g;
kpeter@836
   898
    Node n1 = g.addNode();
kpeter@836
   899
    Node n2 = g.addNode();
kpeter@836
   900
    Node n3 = g.addNode();
alpar@956
   901
kpeter@836
   902
    SmartDigraph::NodeMap<int> map1(g);
kpeter@836
   903
    SmartDigraph::ArcMap<char> map2(g);
kpeter@836
   904
    ConstMap<Node, A> cmap1 = A();
kpeter@836
   905
    ConstMap<Arc, C> cmap2 = C(0);
alpar@956
   906
kpeter@836
   907
    map1[n1] = 10;
kpeter@836
   908
    map1[n2] = 5;
kpeter@836
   909
    map1[n3] = 12;
alpar@956
   910
kpeter@836
   911
    // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
kpeter@836
   912
    check(mapMin(g, map1) == n2, "Wrong mapMin()");
kpeter@836
   913
    check(mapMax(g, map1) == n3, "Wrong mapMax()");
kpeter@836
   914
    check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()");
kpeter@836
   915
    check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()");
kpeter@836
   916
    check(mapMinValue(g, map1) == 5, "Wrong mapMinValue()");
kpeter@836
   917
    check(mapMaxValue(g, map1) == 12, "Wrong mapMaxValue()");
kpeter@836
   918
kpeter@836
   919
    check(mapMin(g, map2) == INVALID, "Wrong mapMin()");
kpeter@836
   920
    check(mapMax(g, map2) == INVALID, "Wrong mapMax()");
kpeter@836
   921
kpeter@836
   922
    check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
kpeter@836
   923
    check(mapMax(g, cmap2) == INVALID, "Wrong mapMax()");
kpeter@836
   924
kpeter@836
   925
    Arc a1 = g.addArc(n1, n2);
kpeter@836
   926
    Arc a2 = g.addArc(n1, n3);
kpeter@836
   927
    Arc a3 = g.addArc(n2, n3);
kpeter@836
   928
    Arc a4 = g.addArc(n3, n1);
alpar@956
   929
kpeter@836
   930
    map2[a1] = 'b';
kpeter@836
   931
    map2[a2] = 'a';
kpeter@836
   932
    map2[a3] = 'b';
kpeter@836
   933
    map2[a4] = 'c';
kpeter@836
   934
kpeter@836
   935
    // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
kpeter@836
   936
    check(mapMin(g, map2) == a2, "Wrong mapMin()");
kpeter@836
   937
    check(mapMax(g, map2) == a4, "Wrong mapMax()");
kpeter@836
   938
    check(mapMin(g, map2, std::greater<int>()) == a4, "Wrong mapMin()");
kpeter@836
   939
    check(mapMax(g, map2, std::greater<int>()) == a2, "Wrong mapMax()");
kpeter@836
   940
    check(mapMinValue(g, map2, std::greater<int>()) == 'c',
kpeter@836
   941
          "Wrong mapMinValue()");
kpeter@836
   942
    check(mapMaxValue(g, map2, std::greater<int>()) == 'a',
kpeter@836
   943
          "Wrong mapMaxValue()");
kpeter@836
   944
kpeter@836
   945
    check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
kpeter@836
   946
    check(mapMax(g, cmap2) != INVALID, "Wrong mapMax()");
kpeter@836
   947
    check(mapMaxValue(g, cmap2) == C(0), "Wrong mapMaxValue()");
kpeter@836
   948
kpeter@836
   949
    check(mapMin(g, composeMap(functorToMap(&createC), map2)) == a2,
kpeter@836
   950
          "Wrong mapMin()");
kpeter@836
   951
    check(mapMax(g, composeMap(functorToMap(&createC), map2)) == a4,
kpeter@836
   952
          "Wrong mapMax()");
kpeter@836
   953
    check(mapMinValue(g, composeMap(functorToMap(&createC), map2)) == C('a'),
kpeter@836
   954
          "Wrong mapMinValue()");
kpeter@836
   955
    check(mapMaxValue(g, composeMap(functorToMap(&createC), map2)) == C('c'),
kpeter@836
   956
          "Wrong mapMaxValue()");
kpeter@836
   957
kpeter@836
   958
    // mapFind(), mapFindIf()
kpeter@836
   959
    check(mapFind(g, map1, 5) == n2, "Wrong mapFind()");
kpeter@836
   960
    check(mapFind(g, map1, 6) == INVALID, "Wrong mapFind()");
kpeter@836
   961
    check(mapFind(g, map2, 'a') == a2, "Wrong mapFind()");
kpeter@836
   962
    check(mapFind(g, map2, 'e') == INVALID, "Wrong mapFind()");
kpeter@836
   963
    check(mapFind(g, cmap2, C(0)) == ArcIt(g), "Wrong mapFind()");
kpeter@836
   964
    check(mapFind(g, cmap2, C(1)) == INVALID, "Wrong mapFind()");
kpeter@836
   965
kpeter@836
   966
    check(mapFindIf(g, map1, Less<int>(7)) == n2,
kpeter@836
   967
          "Wrong mapFindIf()");
kpeter@836
   968
    check(mapFindIf(g, map1, Less<int>(5)) == INVALID,
kpeter@836
   969
          "Wrong mapFindIf()");
kpeter@836
   970
    check(mapFindIf(g, map2, Less<char>('d')) == ArcIt(g),
kpeter@836
   971
          "Wrong mapFindIf()");
kpeter@836
   972
    check(mapFindIf(g, map2, Less<char>('a')) == INVALID,
kpeter@836
   973
          "Wrong mapFindIf()");
kpeter@836
   974
kpeter@836
   975
    // mapCount(), mapCountIf()
kpeter@836
   976
    check(mapCount(g, map1, 5) == 1, "Wrong mapCount()");
kpeter@836
   977
    check(mapCount(g, map1, 6) == 0, "Wrong mapCount()");
kpeter@836
   978
    check(mapCount(g, map2, 'a') == 1, "Wrong mapCount()");
kpeter@836
   979
    check(mapCount(g, map2, 'b') == 2, "Wrong mapCount()");
kpeter@836
   980
    check(mapCount(g, map2, 'e') == 0, "Wrong mapCount()");
kpeter@836
   981
    check(mapCount(g, cmap2, C(0)) == 4, "Wrong mapCount()");
kpeter@836
   982
    check(mapCount(g, cmap2, C(1)) == 0, "Wrong mapCount()");
kpeter@836
   983
kpeter@836
   984
    check(mapCountIf(g, map1, Less<int>(11)) == 2,
kpeter@836
   985
          "Wrong mapCountIf()");
kpeter@836
   986
    check(mapCountIf(g, map1, Less<int>(13)) == 3,
kpeter@836
   987
          "Wrong mapCountIf()");
kpeter@836
   988
    check(mapCountIf(g, map1, Less<int>(5)) == 0,
kpeter@836
   989
          "Wrong mapCountIf()");
kpeter@836
   990
    check(mapCountIf(g, map2, Less<char>('d')) == 4,
kpeter@836
   991
          "Wrong mapCountIf()");
kpeter@836
   992
    check(mapCountIf(g, map2, Less<char>('c')) == 3,
kpeter@836
   993
          "Wrong mapCountIf()");
kpeter@836
   994
    check(mapCountIf(g, map2, Less<char>('a')) == 0,
kpeter@836
   995
          "Wrong mapCountIf()");
alpar@956
   996
kpeter@836
   997
    // MapIt, ConstMapIt
kpeter@836
   998
/*
kpeter@836
   999
These tests can be used after applying bugfix #330
kpeter@836
  1000
    typedef SmartDigraph::NodeMap<int>::MapIt MapIt;
kpeter@836
  1001
    typedef SmartDigraph::NodeMap<int>::ConstMapIt ConstMapIt;
kpeter@836
  1002
    check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5,
kpeter@836
  1003
          "Wrong NodeMap<>::MapIt");
kpeter@836
  1004
    check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12,
kpeter@836
  1005
          "Wrong NodeMap<>::MapIt");
alpar@956
  1006
kpeter@836
  1007
    int sum = 0;
kpeter@836
  1008
    std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum));
kpeter@836
  1009
    check(sum == 27, "Wrong NodeMap<>::MapIt");
kpeter@836
  1010
    std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum));
kpeter@836
  1011
    check(sum == 54, "Wrong NodeMap<>::ConstMapIt");
kpeter@836
  1012
*/
kpeter@836
  1013
kpeter@836
  1014
    // mapCopy(), mapCompare(), mapFill()
kpeter@836
  1015
    check(mapCompare(g, map1, map1), "Wrong mapCompare()");
kpeter@836
  1016
    check(mapCompare(g, cmap2, cmap2), "Wrong mapCompare()");
kpeter@836
  1017
    check(mapCompare(g, map1, shiftMap(map1, 0)), "Wrong mapCompare()");
kpeter@836
  1018
    check(mapCompare(g, map2, scaleMap(map2, 1)), "Wrong mapCompare()");
kpeter@836
  1019
    check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()");
kpeter@836
  1020
kpeter@836
  1021
    SmartDigraph::NodeMap<int> map3(g, 0);
kpeter@836
  1022
    SmartDigraph::ArcMap<char> map4(g, 'a');
alpar@956
  1023
kpeter@836
  1024
    check(!mapCompare(g, map1, map3), "Wrong mapCompare()");
alpar@956
  1025
    check(!mapCompare(g, map2, map4), "Wrong mapCompare()");
alpar@956
  1026
kpeter@836
  1027
    mapCopy(g, map1, map3);
kpeter@836
  1028
    mapCopy(g, map2, map4);
kpeter@836
  1029
kpeter@836
  1030
    check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()");
alpar@956
  1031
    check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()");
alpar@956
  1032
kpeter@836
  1033
    Undirector<SmartDigraph> ug(g);
kpeter@836
  1034
    Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x');
kpeter@836
  1035
    Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14);
alpar@956
  1036
kpeter@836
  1037
    check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
kpeter@836
  1038
    check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
kpeter@836
  1039
    check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
kpeter@836
  1040
    check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
alpar@956
  1041
kpeter@836
  1042
    mapCopy(g, map2, umap1);
kpeter@836
  1043
kpeter@836
  1044
    check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
kpeter@836
  1045
    check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
kpeter@836
  1046
    check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
kpeter@836
  1047
    check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
alpar@956
  1048
kpeter@836
  1049
    mapCopy(g, map2, umap1);
kpeter@836
  1050
    mapCopy(g, umap1, map2);
kpeter@836
  1051
    mapCopy(ug, map2, umap1);
kpeter@836
  1052
    mapCopy(ug, umap1, map2);
alpar@956
  1053
kpeter@836
  1054
    check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
kpeter@836
  1055
    mapCopy(ug, umap1, umap2);
kpeter@836
  1056
    check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
alpar@956
  1057
kpeter@836
  1058
    check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()");
kpeter@836
  1059
    mapFill(g, map1, 2);
kpeter@836
  1060
    check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()");
kpeter@836
  1061
kpeter@836
  1062
    check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()");
kpeter@836
  1063
    mapCopy(g, constMap<Arc>('z'), map2);
kpeter@836
  1064
    check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()");
kpeter@836
  1065
  }
alpar@956
  1066
alpar@25
  1067
  return 0;
alpar@25
  1068
}