test/graph_test.h
author Balazs Dezso <deba@inf.elte.hu>
Sun, 17 Aug 2008 15:02:03 +0200
changeset 1199 15282595e6f4
parent 1092 dceba191c00d
permissions -rw-r--r--
Using Arc instead of ArcIt in Dfs (#32)
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
kpeter@171
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
kpeter@171
     4
 *
alpar@1092
     5
 * Copyright (C) 2003-2013
kpeter@171
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
kpeter@171
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
kpeter@171
     8
 *
kpeter@171
     9
 * Permission to use, modify and distribute this software is granted
kpeter@171
    10
 * provided that this copyright notice appears in all copies. For
kpeter@171
    11
 * precise terms see the accompanying LICENSE file.
kpeter@171
    12
 *
kpeter@171
    13
 * This software is provided "AS IS" with no warranty of any kind,
kpeter@171
    14
 * express or implied, and with no claim as to its suitability for any
kpeter@171
    15
 * purpose.
kpeter@171
    16
 *
kpeter@171
    17
 */
kpeter@171
    18
kpeter@171
    19
#ifndef LEMON_TEST_GRAPH_TEST_H
kpeter@171
    20
#define LEMON_TEST_GRAPH_TEST_H
kpeter@171
    21
deba@228
    22
#include <set>
deba@228
    23
deba@220
    24
#include <lemon/core.h>
deba@228
    25
#include <lemon/maps.h>
deba@228
    26
kpeter@171
    27
#include "test_tools.h"
kpeter@171
    28
kpeter@171
    29
namespace lemon {
kpeter@171
    30
kpeter@171
    31
  template<class Graph>
kpeter@171
    32
  void checkGraphNodeList(const Graph &G, int cnt)
kpeter@171
    33
  {
kpeter@171
    34
    typename Graph::NodeIt n(G);
kpeter@171
    35
    for(int i=0;i<cnt;i++) {
kpeter@171
    36
      check(n!=INVALID,"Wrong Node list linking.");
kpeter@171
    37
      ++n;
kpeter@171
    38
    }
kpeter@171
    39
    check(n==INVALID,"Wrong Node list linking.");
kpeter@171
    40
    check(countNodes(G)==cnt,"Wrong Node number.");
alpar@1131
    41
alpar@1131
    42
#ifdef LEMON_CXX11
alpar@1131
    43
    {
alpar@1131
    44
      typename Graph::NodeIt n(G);
alpar@1131
    45
      for(auto u: G.nodes())
alpar@1131
    46
        {
alpar@1131
    47
          check(n==u,"Wrong STL Node iterator.");
alpar@1131
    48
          ++n;
alpar@1131
    49
        }
alpar@1131
    50
      check(n==INVALID,"Wrong STL Node iterator.");
alpar@1131
    51
    }
alpar@1131
    52
    {
alpar@1131
    53
      typename Graph::NodeIt n(G);
alpar@1131
    54
      for(typename Graph::Node u: G.nodes())
alpar@1131
    55
        {
alpar@1131
    56
          check(n==u,"Wrong STL Node iterator.");
alpar@1131
    57
          ++n;
alpar@1131
    58
        }
alpar@1131
    59
      check(n==INVALID,"Wrong STL Node iterator.");
alpar@1131
    60
    }
alpar@1131
    61
#endif
kpeter@171
    62
  }
kpeter@171
    63
kpeter@171
    64
  template<class Graph>
deba@1019
    65
  void checkGraphRedNodeList(const Graph &G, int cnt)
deba@1019
    66
  {
deba@1026
    67
    typename Graph::RedNodeIt n(G);
deba@1019
    68
    for(int i=0;i<cnt;i++) {
deba@1019
    69
      check(n!=INVALID,"Wrong red Node list linking.");
deba@1025
    70
      check(G.red(n),"Wrong node set check.");
deba@1025
    71
      check(!G.blue(n),"Wrong node set check.");
deba@1025
    72
      typename Graph::Node nn = n;
deba@1025
    73
      check(G.asRedNodeUnsafe(nn) == n,"Wrong node conversion.");
deba@1025
    74
      check(G.asRedNode(nn) == n,"Wrong node conversion.");
deba@1025
    75
      check(G.asBlueNode(nn) == INVALID,"Wrong node conversion.");
deba@1019
    76
      ++n;
deba@1019
    77
    }
deba@1019
    78
    check(n==INVALID,"Wrong red Node list linking.");
deba@1019
    79
    check(countRedNodes(G)==cnt,"Wrong red Node number.");
alpar@1131
    80
#ifdef LEMON_CXX11
alpar@1131
    81
    {
alpar@1131
    82
      typename Graph::RedNodeIt n(G);
alpar@1131
    83
      for(auto u: G.redNodes())
alpar@1131
    84
        {
alpar@1131
    85
          check(n==u,"Wrong STL RedNode iterator.");
alpar@1131
    86
          ++n;
alpar@1131
    87
        }
alpar@1131
    88
      check(n==INVALID,"Wrong STL RedNode iterator.");
alpar@1131
    89
    }
alpar@1131
    90
    {
alpar@1131
    91
      typename Graph::RedNodeIt n(G);
alpar@1131
    92
      for(typename Graph::RedNode u: G.redNodes())
alpar@1131
    93
        {
alpar@1131
    94
          check(n==u,"Wrong STL RedNode iterator.");
alpar@1131
    95
          ++n;
alpar@1131
    96
        }
alpar@1131
    97
      check(n==INVALID,"Wrong STL RedNode iterator.");
alpar@1131
    98
    }
alpar@1131
    99
#endif
deba@1019
   100
  }
deba@1019
   101
deba@1019
   102
  template<class Graph>
deba@1019
   103
  void checkGraphBlueNodeList(const Graph &G, int cnt)
deba@1019
   104
  {
deba@1026
   105
    typename Graph::BlueNodeIt n(G);
deba@1019
   106
    for(int i=0;i<cnt;i++) {
deba@1019
   107
      check(n!=INVALID,"Wrong blue Node list linking.");
deba@1025
   108
      check(G.blue(n),"Wrong node set check.");
deba@1025
   109
      check(!G.red(n),"Wrong node set check.");
deba@1025
   110
      typename Graph::Node nn = n;
deba@1025
   111
      check(G.asBlueNodeUnsafe(nn) == n,"Wrong node conversion.");
deba@1025
   112
      check(G.asBlueNode(nn) == n,"Wrong node conversion.");
deba@1025
   113
      check(G.asRedNode(nn) == INVALID,"Wrong node conversion.");
deba@1019
   114
      ++n;
deba@1019
   115
    }
deba@1019
   116
    check(n==INVALID,"Wrong blue Node list linking.");
deba@1019
   117
    check(countBlueNodes(G)==cnt,"Wrong blue Node number.");
alpar@1131
   118
#ifdef LEMON_CXX11
alpar@1131
   119
    {
alpar@1131
   120
      typename Graph::BlueNodeIt n(G);
alpar@1131
   121
      for(auto u: G.blueNodes())
alpar@1131
   122
        {
alpar@1131
   123
          check(n==u,"Wrong STL BlueNode iterator.");
alpar@1131
   124
          ++n;
alpar@1131
   125
        }
alpar@1131
   126
      check(n==INVALID,"Wrong STL BlueNode iterator.");
alpar@1131
   127
    }
alpar@1131
   128
    {
alpar@1131
   129
      typename Graph::BlueNodeIt n(G);
alpar@1131
   130
      for(typename Graph::BlueNode u: G.blueNodes())
alpar@1131
   131
        {
alpar@1131
   132
          check(n==u,"Wrong STL BlueNode iterator.");
alpar@1131
   133
          ++n;
alpar@1131
   134
        }
alpar@1131
   135
      check(n==INVALID,"Wrong STL BlueNode iterator.");
alpar@1131
   136
    }
alpar@1131
   137
#endif
alpar@1131
   138
deba@1019
   139
  }
deba@1019
   140
deba@1019
   141
  template<class Graph>
kpeter@171
   142
  void checkGraphArcList(const Graph &G, int cnt)
kpeter@171
   143
  {
kpeter@171
   144
    typename Graph::ArcIt e(G);
kpeter@171
   145
    for(int i=0;i<cnt;i++) {
kpeter@171
   146
      check(e!=INVALID,"Wrong Arc list linking.");
deba@228
   147
      check(G.oppositeNode(G.source(e), e) == G.target(e),
deba@228
   148
            "Wrong opposite node");
deba@228
   149
      check(G.oppositeNode(G.target(e), e) == G.source(e),
deba@228
   150
            "Wrong opposite node");
kpeter@171
   151
      ++e;
kpeter@171
   152
    }
kpeter@171
   153
    check(e==INVALID,"Wrong Arc list linking.");
kpeter@171
   154
    check(countArcs(G)==cnt,"Wrong Arc number.");
alpar@1131
   155
#ifdef LEMON_CXX11
alpar@1131
   156
    {
alpar@1131
   157
      typename Graph::ArcIt a(G);
alpar@1131
   158
      for(auto e: G.arcs())
alpar@1131
   159
        {
alpar@1131
   160
          check(a==e,"Wrong STL Arc iterator.");
alpar@1131
   161
          ++a;
alpar@1131
   162
        }
alpar@1131
   163
      check(a==INVALID,"Wrong STL Arc iterator.");
alpar@1131
   164
    }
alpar@1131
   165
    {
alpar@1131
   166
      typename Graph::ArcIt a(G);
alpar@1131
   167
      for(typename Graph::Arc e: G.arcs())
alpar@1131
   168
        {
alpar@1131
   169
          check(a==e,"Wrong STL Arc iterator.");
alpar@1131
   170
          ++a;
alpar@1131
   171
        }
alpar@1131
   172
      check(a==INVALID,"Wrong STL Arc iterator.");
alpar@1131
   173
    }
alpar@1131
   174
#endif
alpar@1131
   175
kpeter@171
   176
  }
kpeter@171
   177
kpeter@171
   178
  template<class Graph>
kpeter@171
   179
  void checkGraphOutArcList(const Graph &G, typename Graph::Node n, int cnt)
kpeter@171
   180
  {
kpeter@171
   181
    typename Graph::OutArcIt e(G,n);
kpeter@171
   182
    for(int i=0;i<cnt;i++) {
kpeter@171
   183
      check(e!=INVALID,"Wrong OutArc list linking.");
kpeter@171
   184
      check(n==G.source(e),"Wrong OutArc list linking.");
deba@228
   185
      check(n==G.baseNode(e),"Wrong OutArc list linking.");
deba@228
   186
      check(G.target(e)==G.runningNode(e),"Wrong OutArc list linking.");
kpeter@171
   187
      ++e;
kpeter@171
   188
    }
kpeter@171
   189
    check(e==INVALID,"Wrong OutArc list linking.");
kpeter@171
   190
    check(countOutArcs(G,n)==cnt,"Wrong OutArc number.");
alpar@1131
   191
#ifdef LEMON_CXX11
alpar@1131
   192
    {
alpar@1131
   193
      typename Graph::OutArcIt a(G,n);
alpar@1131
   194
      for(auto e: G.outArcs(n))
alpar@1131
   195
        {
alpar@1131
   196
          check(a==e,"Wrong STL OutArc iterator.");
alpar@1131
   197
          ++a;
alpar@1131
   198
        }
alpar@1131
   199
      check(a==INVALID,"Wrong STL OutArc iterator.");
alpar@1131
   200
    }
alpar@1131
   201
    {
alpar@1131
   202
      typename Graph::OutArcIt a(G,n);
alpar@1131
   203
      for(typename Graph::Arc e: G.outArcs(n))
alpar@1131
   204
        {
alpar@1131
   205
          check(a==e,"Wrong STL OutArc iterator.");
alpar@1131
   206
          ++a;
alpar@1131
   207
        }
alpar@1131
   208
      check(a==INVALID,"Wrong STL OutArc iterator.");
alpar@1131
   209
    }
alpar@1131
   210
#endif
alpar@1131
   211
kpeter@171
   212
  }
kpeter@171
   213
kpeter@171
   214
  template<class Graph>
kpeter@171
   215
  void checkGraphInArcList(const Graph &G, typename Graph::Node n, int cnt)
kpeter@171
   216
  {
kpeter@171
   217
    typename Graph::InArcIt e(G,n);
kpeter@171
   218
    for(int i=0;i<cnt;i++) {
kpeter@171
   219
      check(e!=INVALID,"Wrong InArc list linking.");
kpeter@171
   220
      check(n==G.target(e),"Wrong InArc list linking.");
deba@228
   221
      check(n==G.baseNode(e),"Wrong OutArc list linking.");
deba@228
   222
      check(G.source(e)==G.runningNode(e),"Wrong OutArc list linking.");
kpeter@171
   223
      ++e;
kpeter@171
   224
    }
kpeter@171
   225
    check(e==INVALID,"Wrong InArc list linking.");
kpeter@171
   226
    check(countInArcs(G,n)==cnt,"Wrong InArc number.");
alpar@1131
   227
#ifdef LEMON_CXX11
alpar@1131
   228
    {
alpar@1131
   229
      typename Graph::InArcIt a(G,n);
alpar@1131
   230
      for(auto e: G.inArcs(n))
alpar@1131
   231
        {
alpar@1131
   232
          check(a==e,"Wrong STL InArc iterator.");
alpar@1131
   233
          ++a;
alpar@1131
   234
        }
alpar@1131
   235
      check(a==INVALID,"Wrong STL InArc iterator.");
alpar@1131
   236
    }
alpar@1131
   237
    {
alpar@1131
   238
      typename Graph::InArcIt a(G,n);
alpar@1131
   239
      for(typename Graph::Arc e: G.inArcs(n))
alpar@1131
   240
        {
alpar@1131
   241
          check(a==e,"Wrong STL InArc iterator.");
alpar@1131
   242
          ++a;
alpar@1131
   243
        }
alpar@1131
   244
      check(a==INVALID,"Wrong STL InArc iterator.");
alpar@1131
   245
    }
alpar@1131
   246
#endif
kpeter@171
   247
  }
kpeter@171
   248
kpeter@171
   249
  template<class Graph>
kpeter@171
   250
  void checkGraphEdgeList(const Graph &G, int cnt)
kpeter@171
   251
  {
kpeter@171
   252
    typename Graph::EdgeIt e(G);
kpeter@171
   253
    for(int i=0;i<cnt;i++) {
kpeter@171
   254
      check(e!=INVALID,"Wrong Edge list linking.");
deba@228
   255
      check(G.oppositeNode(G.u(e), e) == G.v(e), "Wrong opposite node");
deba@228
   256
      check(G.oppositeNode(G.v(e), e) == G.u(e), "Wrong opposite node");
kpeter@171
   257
      ++e;
kpeter@171
   258
    }
kpeter@171
   259
    check(e==INVALID,"Wrong Edge list linking.");
kpeter@171
   260
    check(countEdges(G)==cnt,"Wrong Edge number.");
alpar@1131
   261
#ifdef LEMON_CXX11
alpar@1131
   262
    {
alpar@1131
   263
      typename Graph::EdgeIt a(G);
alpar@1131
   264
      for(auto e: G.edges())
alpar@1131
   265
        {
alpar@1131
   266
          check(a==e,"Wrong STL Edge iterator.");
alpar@1131
   267
          ++a;
alpar@1131
   268
        }
alpar@1131
   269
      check(a==INVALID,"Wrong STL Edge iterator.");
alpar@1131
   270
    }
alpar@1131
   271
    {
alpar@1131
   272
      typename Graph::EdgeIt a(G);
alpar@1131
   273
      for(typename Graph::Edge e: G.edges())
alpar@1131
   274
        {
alpar@1131
   275
          check(a==e,"Wrong STL Edge iterator.");
alpar@1131
   276
          ++a;
alpar@1131
   277
        }
alpar@1131
   278
      check(a==INVALID,"Wrong STL Edge iterator.");
alpar@1131
   279
    }
alpar@1131
   280
#endif
alpar@1131
   281
kpeter@171
   282
  }
kpeter@171
   283
kpeter@171
   284
  template<class Graph>
kpeter@171
   285
  void checkGraphIncEdgeList(const Graph &G, typename Graph::Node n, int cnt)
kpeter@171
   286
  {
kpeter@171
   287
    typename Graph::IncEdgeIt e(G,n);
kpeter@171
   288
    for(int i=0;i<cnt;i++) {
kpeter@171
   289
      check(e!=INVALID,"Wrong IncEdge list linking.");
kpeter@171
   290
      check(n==G.u(e) || n==G.v(e),"Wrong IncEdge list linking.");
deba@228
   291
      check(n==G.baseNode(e),"Wrong OutArc list linking.");
deba@228
   292
      check(G.u(e)==G.runningNode(e) || G.v(e)==G.runningNode(e),
deba@228
   293
            "Wrong OutArc list linking.");
kpeter@171
   294
      ++e;
kpeter@171
   295
    }
kpeter@171
   296
    check(e==INVALID,"Wrong IncEdge list linking.");
kpeter@171
   297
    check(countIncEdges(G,n)==cnt,"Wrong IncEdge number.");
alpar@1131
   298
#ifdef LEMON_CXX11
alpar@1131
   299
    {
alpar@1131
   300
      typename Graph::IncEdgeIt a(G,n);
alpar@1131
   301
      for(auto e: G.incEdges(n))
alpar@1131
   302
        {
alpar@1131
   303
          check(a==e,"Wrong STL IncEdge iterator.");
alpar@1131
   304
          ++a;
alpar@1131
   305
        }
alpar@1131
   306
      check(a==INVALID,"Wrong STL IncEdge iterator.");
alpar@1131
   307
    }
alpar@1131
   308
    {
alpar@1131
   309
      typename Graph::IncEdgeIt a(G,n);
alpar@1131
   310
      for(typename Graph::Edge e: G.incEdges(n))
alpar@1131
   311
        {
alpar@1131
   312
          check(a==e,"Wrong STL IncEdge iterator.");
alpar@1131
   313
          ++a;
alpar@1131
   314
        }
alpar@1131
   315
      check(a==INVALID,"Wrong STL IncEdge iterator.");
alpar@1131
   316
    }
alpar@1131
   317
#endif
alpar@1131
   318
kpeter@171
   319
  }
kpeter@171
   320
deba@228
   321
  template <class Graph>
kpeter@374
   322
  void checkGraphIncEdgeArcLists(const Graph &G, typename Graph::Node n,
kpeter@374
   323
                                 int cnt)
kpeter@374
   324
  {
kpeter@374
   325
    checkGraphIncEdgeList(G, n, cnt);
kpeter@374
   326
    checkGraphOutArcList(G, n, cnt);
kpeter@374
   327
    checkGraphInArcList(G, n, cnt);
kpeter@374
   328
  }
kpeter@374
   329
kpeter@374
   330
  template <class Graph>
deba@228
   331
  void checkGraphConArcList(const Graph &G, int cnt) {
deba@228
   332
    int i = 0;
deba@228
   333
    for (typename Graph::NodeIt u(G); u != INVALID; ++u) {
deba@228
   334
      for (typename Graph::NodeIt v(G); v != INVALID; ++v) {
deba@228
   335
        for (ConArcIt<Graph> a(G, u, v); a != INVALID; ++a) {
deba@228
   336
          check(G.source(a) == u, "Wrong iterator.");
deba@228
   337
          check(G.target(a) == v, "Wrong iterator.");
deba@228
   338
          ++i;
deba@228
   339
        }
deba@228
   340
      }
deba@228
   341
    }
deba@228
   342
    check(cnt == i, "Wrong iterator.");
kpeter@171
   343
  }
kpeter@171
   344
kpeter@171
   345
  template <class Graph>
deba@228
   346
  void checkGraphConEdgeList(const Graph &G, int cnt) {
deba@228
   347
    int i = 0;
deba@228
   348
    for (typename Graph::NodeIt u(G); u != INVALID; ++u) {
deba@228
   349
      for (typename Graph::NodeIt v(G); v != INVALID; ++v) {
deba@228
   350
        for (ConEdgeIt<Graph> e(G, u, v); e != INVALID; ++e) {
deba@228
   351
          check((G.u(e) == u && G.v(e) == v) ||
deba@228
   352
                (G.u(e) == v && G.v(e) == u), "Wrong iterator.");
deba@228
   353
          i += u == v ? 2 : 1;
deba@228
   354
        }
deba@228
   355
      }
deba@228
   356
    }
deba@228
   357
    check(2 * cnt == i, "Wrong iterator.");
kpeter@171
   358
  }
kpeter@171
   359
deba@228
   360
  template <typename Graph>
deba@228
   361
  void checkArcDirections(const Graph& G) {
deba@228
   362
    for (typename Graph::ArcIt a(G); a != INVALID; ++a) {
deba@228
   363
      check(G.source(a) == G.target(G.oppositeArc(a)), "Wrong direction");
deba@228
   364
      check(G.target(a) == G.source(G.oppositeArc(a)), "Wrong direction");
deba@228
   365
      check(G.direct(a, G.direction(a)) == a, "Wrong direction");
kpeter@171
   366
    }
kpeter@171
   367
  }
kpeter@171
   368
deba@228
   369
  template <typename Graph>
deba@228
   370
  void checkNodeIds(const Graph& G) {
deba@1019
   371
    typedef typename Graph::Node Node;
deba@228
   372
    std::set<int> values;
deba@228
   373
    for (typename Graph::NodeIt n(G); n != INVALID; ++n) {
deba@228
   374
      check(G.nodeFromId(G.id(n)) == n, "Wrong id");
deba@228
   375
      check(values.find(G.id(n)) == values.end(), "Wrong id");
deba@228
   376
      check(G.id(n) <= G.maxNodeId(), "Wrong maximum id");
deba@228
   377
      values.insert(G.id(n));
kpeter@171
   378
    }
deba@1019
   379
    check(G.maxId(Node()) <= G.maxNodeId(), "Wrong maximum id");
deba@1019
   380
  }
deba@1019
   381
deba@1019
   382
  template <typename Graph>
deba@1019
   383
  void checkRedNodeIds(const Graph& G) {
deba@1019
   384
    typedef typename Graph::RedNode RedNode;
deba@1019
   385
    std::set<int> values;
deba@1026
   386
    for (typename Graph::RedNodeIt n(G); n != INVALID; ++n) {
deba@1019
   387
      check(G.red(n), "Wrong partition");
deba@1025
   388
      check(values.find(G.id(n)) == values.end(), "Wrong id");
deba@1025
   389
      check(G.id(n) <= G.maxRedId(), "Wrong maximum id");
deba@1019
   390
      values.insert(G.id(n));
deba@1019
   391
    }
deba@1019
   392
    check(G.maxId(RedNode()) == G.maxRedId(), "Wrong maximum id");
deba@1019
   393
  }
deba@1019
   394
deba@1019
   395
  template <typename Graph>
deba@1019
   396
  void checkBlueNodeIds(const Graph& G) {
deba@1019
   397
    typedef typename Graph::BlueNode BlueNode;
deba@1019
   398
    std::set<int> values;
deba@1026
   399
    for (typename Graph::BlueNodeIt n(G); n != INVALID; ++n) {
deba@1019
   400
      check(G.blue(n), "Wrong partition");
deba@1025
   401
      check(values.find(G.id(n)) == values.end(), "Wrong id");
deba@1025
   402
      check(G.id(n) <= G.maxBlueId(), "Wrong maximum id");
deba@1019
   403
      values.insert(G.id(n));
deba@1019
   404
    }
deba@1019
   405
    check(G.maxId(BlueNode()) == G.maxBlueId(), "Wrong maximum id");
kpeter@171
   406
  }
kpeter@171
   407
deba@228
   408
  template <typename Graph>
deba@228
   409
  void checkArcIds(const Graph& G) {
deba@1019
   410
    typedef typename Graph::Arc Arc;
deba@228
   411
    std::set<int> values;
deba@228
   412
    for (typename Graph::ArcIt a(G); a != INVALID; ++a) {
deba@228
   413
      check(G.arcFromId(G.id(a)) == a, "Wrong id");
deba@228
   414
      check(values.find(G.id(a)) == values.end(), "Wrong id");
deba@228
   415
      check(G.id(a) <= G.maxArcId(), "Wrong maximum id");
deba@228
   416
      values.insert(G.id(a));
deba@228
   417
    }
deba@1019
   418
    check(G.maxId(Arc()) <= G.maxArcId(), "Wrong maximum id");
kpeter@171
   419
  }
alpar@209
   420
deba@228
   421
  template <typename Graph>
deba@228
   422
  void checkEdgeIds(const Graph& G) {
deba@1019
   423
    typedef typename Graph::Edge Edge;
deba@228
   424
    std::set<int> values;
deba@228
   425
    for (typename Graph::EdgeIt e(G); e != INVALID; ++e) {
deba@228
   426
      check(G.edgeFromId(G.id(e)) == e, "Wrong id");
deba@228
   427
      check(values.find(G.id(e)) == values.end(), "Wrong id");
deba@228
   428
      check(G.id(e) <= G.maxEdgeId(), "Wrong maximum id");
deba@228
   429
      values.insert(G.id(e));
deba@228
   430
    }
deba@1019
   431
    check(G.maxId(Edge()) <= G.maxEdgeId(), "Wrong maximum id");
kpeter@171
   432
  }
kpeter@171
   433
deba@228
   434
  template <typename Graph>
deba@228
   435
  void checkGraphNodeMap(const Graph& G) {
deba@228
   436
    typedef typename Graph::Node Node;
deba@228
   437
    typedef typename Graph::NodeIt NodeIt;
deba@228
   438
deba@228
   439
    typedef typename Graph::template NodeMap<int> IntNodeMap;
deba@228
   440
    IntNodeMap map(G, 42);
deba@228
   441
    for (NodeIt it(G); it != INVALID; ++it) {
deba@228
   442
      check(map[it] == 42, "Wrong map constructor.");
deba@228
   443
    }
deba@228
   444
    int s = 0;
deba@228
   445
    for (NodeIt it(G); it != INVALID; ++it) {
deba@228
   446
      map[it] = 0;
deba@228
   447
      check(map[it] == 0, "Wrong operator[].");
deba@228
   448
      map.set(it, s);
deba@228
   449
      check(map[it] == s, "Wrong set.");
deba@228
   450
      ++s;
deba@228
   451
    }
deba@228
   452
    s = s * (s - 1) / 2;
deba@228
   453
    for (NodeIt it(G); it != INVALID; ++it) {
deba@228
   454
      s -= map[it];
deba@228
   455
    }
deba@228
   456
    check(s == 0, "Wrong sum.");
deba@228
   457
kpeter@263
   458
    // map = constMap<Node>(12);
kpeter@263
   459
    // for (NodeIt it(G); it != INVALID; ++it) {
kpeter@263
   460
    //   check(map[it] == 12, "Wrong operator[].");
kpeter@263
   461
    // }
deba@228
   462
  }
deba@228
   463
deba@228
   464
  template <typename Graph>
deba@1026
   465
  void checkGraphRedNodeMap(const Graph& G) {
deba@1019
   466
    typedef typename Graph::Node Node;
deba@1026
   467
    typedef typename Graph::RedNodeIt RedNodeIt;
deba@1019
   468
deba@1026
   469
    typedef typename Graph::template RedNodeMap<int> IntRedNodeMap;
deba@1026
   470
    IntRedNodeMap map(G, 42);
deba@1026
   471
    for (RedNodeIt it(G); it != INVALID; ++it) {
deba@1019
   472
      check(map[it] == 42, "Wrong map constructor.");
deba@1019
   473
    }
deba@1019
   474
    int s = 0;
deba@1026
   475
    for (RedNodeIt it(G); it != INVALID; ++it) {
deba@1019
   476
      map[it] = 0;
deba@1019
   477
      check(map[it] == 0, "Wrong operator[].");
deba@1019
   478
      map.set(it, s);
deba@1019
   479
      check(map[it] == s, "Wrong set.");
deba@1019
   480
      ++s;
deba@1019
   481
    }
deba@1019
   482
    s = s * (s - 1) / 2;
deba@1026
   483
    for (RedNodeIt it(G); it != INVALID; ++it) {
deba@1019
   484
      s -= map[it];
deba@1019
   485
    }
deba@1019
   486
    check(s == 0, "Wrong sum.");
deba@1019
   487
deba@1019
   488
    // map = constMap<Node>(12);
deba@1019
   489
    // for (NodeIt it(G); it != INVALID; ++it) {
deba@1019
   490
    //   check(map[it] == 12, "Wrong operator[].");
deba@1019
   491
    // }
deba@1019
   492
  }
deba@1019
   493
deba@1019
   494
  template <typename Graph>
deba@1026
   495
  void checkGraphBlueNodeMap(const Graph& G) {
deba@1019
   496
    typedef typename Graph::Node Node;
deba@1026
   497
    typedef typename Graph::BlueNodeIt BlueNodeIt;
deba@1019
   498
deba@1026
   499
    typedef typename Graph::template BlueNodeMap<int> IntBlueNodeMap;
deba@1026
   500
    IntBlueNodeMap map(G, 42);
deba@1026
   501
    for (BlueNodeIt it(G); it != INVALID; ++it) {
deba@1019
   502
      check(map[it] == 42, "Wrong map constructor.");
deba@1019
   503
    }
deba@1019
   504
    int s = 0;
deba@1026
   505
    for (BlueNodeIt it(G); it != INVALID; ++it) {
deba@1019
   506
      map[it] = 0;
deba@1019
   507
      check(map[it] == 0, "Wrong operator[].");
deba@1019
   508
      map.set(it, s);
deba@1019
   509
      check(map[it] == s, "Wrong set.");
deba@1019
   510
      ++s;
deba@1019
   511
    }
deba@1019
   512
    s = s * (s - 1) / 2;
deba@1026
   513
    for (BlueNodeIt it(G); it != INVALID; ++it) {
deba@1019
   514
      s -= map[it];
deba@1019
   515
    }
deba@1019
   516
    check(s == 0, "Wrong sum.");
deba@1019
   517
deba@1019
   518
    // map = constMap<Node>(12);
deba@1019
   519
    // for (NodeIt it(G); it != INVALID; ++it) {
deba@1019
   520
    //   check(map[it] == 12, "Wrong operator[].");
deba@1019
   521
    // }
deba@1019
   522
  }
deba@1019
   523
deba@1019
   524
  template <typename Graph>
deba@228
   525
  void checkGraphArcMap(const Graph& G) {
deba@228
   526
    typedef typename Graph::Arc Arc;
deba@228
   527
    typedef typename Graph::ArcIt ArcIt;
deba@228
   528
deba@228
   529
    typedef typename Graph::template ArcMap<int> IntArcMap;
deba@228
   530
    IntArcMap map(G, 42);
deba@228
   531
    for (ArcIt it(G); it != INVALID; ++it) {
deba@228
   532
      check(map[it] == 42, "Wrong map constructor.");
deba@228
   533
    }
deba@228
   534
    int s = 0;
deba@228
   535
    for (ArcIt it(G); it != INVALID; ++it) {
deba@228
   536
      map[it] = 0;
deba@228
   537
      check(map[it] == 0, "Wrong operator[].");
deba@228
   538
      map.set(it, s);
deba@228
   539
      check(map[it] == s, "Wrong set.");
deba@228
   540
      ++s;
deba@228
   541
    }
deba@228
   542
    s = s * (s - 1) / 2;
deba@228
   543
    for (ArcIt it(G); it != INVALID; ++it) {
deba@228
   544
      s -= map[it];
deba@228
   545
    }
deba@228
   546
    check(s == 0, "Wrong sum.");
deba@228
   547
kpeter@263
   548
    // map = constMap<Arc>(12);
kpeter@263
   549
    // for (ArcIt it(G); it != INVALID; ++it) {
kpeter@263
   550
    //   check(map[it] == 12, "Wrong operator[].");
kpeter@263
   551
    // }
deba@228
   552
  }
deba@228
   553
deba@228
   554
  template <typename Graph>
deba@228
   555
  void checkGraphEdgeMap(const Graph& G) {
deba@228
   556
    typedef typename Graph::Edge Edge;
deba@228
   557
    typedef typename Graph::EdgeIt EdgeIt;
deba@228
   558
deba@228
   559
    typedef typename Graph::template EdgeMap<int> IntEdgeMap;
deba@228
   560
    IntEdgeMap map(G, 42);
deba@228
   561
    for (EdgeIt it(G); it != INVALID; ++it) {
deba@228
   562
      check(map[it] == 42, "Wrong map constructor.");
deba@228
   563
    }
deba@228
   564
    int s = 0;
deba@228
   565
    for (EdgeIt it(G); it != INVALID; ++it) {
deba@228
   566
      map[it] = 0;
deba@228
   567
      check(map[it] == 0, "Wrong operator[].");
deba@228
   568
      map.set(it, s);
deba@228
   569
      check(map[it] == s, "Wrong set.");
deba@228
   570
      ++s;
deba@228
   571
    }
deba@228
   572
    s = s * (s - 1) / 2;
deba@228
   573
    for (EdgeIt it(G); it != INVALID; ++it) {
deba@228
   574
      s -= map[it];
deba@228
   575
    }
deba@228
   576
    check(s == 0, "Wrong sum.");
deba@228
   577
kpeter@263
   578
    // map = constMap<Edge>(12);
kpeter@263
   579
    // for (EdgeIt it(G); it != INVALID; ++it) {
kpeter@263
   580
    //   check(map[it] == 12, "Wrong operator[].");
kpeter@263
   581
    // }
deba@228
   582
  }
deba@228
   583
deba@228
   584
kpeter@171
   585
} //namespace lemon
kpeter@171
   586
kpeter@171
   587
#endif