test/digraph_test.cc
author Peter Kovacs <kpeter@inf.elte.hu>
Thu, 17 Oct 2013 09:30:57 +0200
changeset 1110 c0c2f5c87aa6
parent 998 7fdaa05a69a1
child 1084 8b2d4e5d96e4
permissions -rw-r--r--
Rename field in min cost flow codes (#478)
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@57
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@57
     4
 *
alpar@877
     5
 * Copyright (C) 2003-2010
deba@57
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@57
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@57
     8
 *
deba@57
     9
 * Permission to use, modify and distribute this software is granted
deba@57
    10
 * provided that this copyright notice appears in all copies. For
deba@57
    11
 * precise terms see the accompanying LICENSE file.
deba@57
    12
 *
deba@57
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@57
    14
 * express or implied, and with no claim as to its suitability for any
deba@57
    15
 * purpose.
deba@57
    16
 *
deba@57
    17
 */
deba@57
    18
deba@57
    19
#include <lemon/concepts/digraph.h>
deba@57
    20
#include <lemon/list_graph.h>
kpeter@171
    21
#include <lemon/smart_graph.h>
kpeter@774
    22
#include <lemon/static_graph.h>
deba@353
    23
#include <lemon/full_graph.h>
deba@57
    24
deba@57
    25
#include "test_tools.h"
kpeter@171
    26
#include "graph_test.h"
deba@57
    27
deba@57
    28
using namespace lemon;
deba@57
    29
using namespace lemon::concepts;
deba@57
    30
deba@228
    31
template <class Digraph>
kpeter@374
    32
void checkDigraphBuild() {
deba@228
    33
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
deba@228
    34
  Digraph G;
deba@228
    35
deba@228
    36
  checkGraphNodeList(G, 0);
deba@228
    37
  checkGraphArcList(G, 0);
deba@228
    38
kpeter@736
    39
  G.reserveNode(3);
kpeter@736
    40
  G.reserveArc(4);
kpeter@736
    41
deba@228
    42
  Node
deba@228
    43
    n1 = G.addNode(),
deba@228
    44
    n2 = G.addNode(),
deba@228
    45
    n3 = G.addNode();
deba@228
    46
  checkGraphNodeList(G, 3);
deba@228
    47
  checkGraphArcList(G, 0);
deba@228
    48
deba@228
    49
  Arc a1 = G.addArc(n1, n2);
deba@228
    50
  check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc");
deba@228
    51
  checkGraphNodeList(G, 3);
deba@228
    52
  checkGraphArcList(G, 1);
deba@228
    53
deba@228
    54
  checkGraphOutArcList(G, n1, 1);
deba@228
    55
  checkGraphOutArcList(G, n2, 0);
deba@228
    56
  checkGraphOutArcList(G, n3, 0);
deba@228
    57
deba@228
    58
  checkGraphInArcList(G, n1, 0);
deba@228
    59
  checkGraphInArcList(G, n2, 1);
deba@228
    60
  checkGraphInArcList(G, n3, 0);
deba@228
    61
deba@228
    62
  checkGraphConArcList(G, 1);
deba@228
    63
kpeter@374
    64
  Arc a2 = G.addArc(n2, n1),
kpeter@374
    65
      a3 = G.addArc(n2, n3),
kpeter@374
    66
      a4 = G.addArc(n2, n3);
alpar@997
    67
  ignore_unused_variable_warning(a2,a3,a4);
kpeter@374
    68
kpeter@374
    69
  checkGraphNodeList(G, 3);
kpeter@374
    70
  checkGraphArcList(G, 4);
kpeter@374
    71
kpeter@374
    72
  checkGraphOutArcList(G, n1, 1);
kpeter@374
    73
  checkGraphOutArcList(G, n2, 3);
kpeter@374
    74
  checkGraphOutArcList(G, n3, 0);
kpeter@374
    75
kpeter@374
    76
  checkGraphInArcList(G, n1, 1);
kpeter@374
    77
  checkGraphInArcList(G, n2, 1);
kpeter@374
    78
  checkGraphInArcList(G, n3, 2);
kpeter@374
    79
kpeter@374
    80
  checkGraphConArcList(G, 4);
kpeter@374
    81
kpeter@374
    82
  checkNodeIds(G);
kpeter@374
    83
  checkArcIds(G);
kpeter@374
    84
  checkGraphNodeMap(G);
kpeter@374
    85
  checkGraphArcMap(G);
kpeter@374
    86
}
kpeter@374
    87
kpeter@374
    88
template <class Digraph>
kpeter@374
    89
void checkDigraphSplit() {
kpeter@374
    90
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@374
    91
kpeter@374
    92
  Digraph G;
kpeter@374
    93
  Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
kpeter@374
    94
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
kpeter@374
    95
      a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
alpar@997
    96
  ignore_unused_variable_warning(a1,a2,a3,a4);
kpeter@374
    97
kpeter@374
    98
  Node n4 = G.split(n2);
kpeter@374
    99
kpeter@374
   100
  check(G.target(OutArcIt(G, n2)) == n4 &&
kpeter@374
   101
        G.source(InArcIt(G, n4)) == n2,
kpeter@374
   102
        "Wrong split.");
kpeter@374
   103
kpeter@374
   104
  checkGraphNodeList(G, 4);
kpeter@374
   105
  checkGraphArcList(G, 5);
kpeter@374
   106
kpeter@374
   107
  checkGraphOutArcList(G, n1, 1);
kpeter@374
   108
  checkGraphOutArcList(G, n2, 1);
kpeter@374
   109
  checkGraphOutArcList(G, n3, 0);
kpeter@374
   110
  checkGraphOutArcList(G, n4, 3);
kpeter@374
   111
kpeter@374
   112
  checkGraphInArcList(G, n1, 1);
kpeter@374
   113
  checkGraphInArcList(G, n2, 1);
kpeter@374
   114
  checkGraphInArcList(G, n3, 2);
kpeter@374
   115
  checkGraphInArcList(G, n4, 1);
kpeter@374
   116
kpeter@374
   117
  checkGraphConArcList(G, 5);
kpeter@374
   118
}
kpeter@374
   119
kpeter@374
   120
template <class Digraph>
kpeter@374
   121
void checkDigraphAlter() {
kpeter@374
   122
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@374
   123
kpeter@374
   124
  Digraph G;
kpeter@374
   125
  Node n1 = G.addNode(), n2 = G.addNode(),
kpeter@374
   126
       n3 = G.addNode(), n4 = G.addNode();
kpeter@374
   127
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1),
kpeter@374
   128
      a3 = G.addArc(n4, n3), a4 = G.addArc(n4, n3),
kpeter@374
   129
      a5 = G.addArc(n2, n4);
alpar@997
   130
  ignore_unused_variable_warning(a1,a2,a3,a5);
kpeter@374
   131
kpeter@374
   132
  checkGraphNodeList(G, 4);
kpeter@374
   133
  checkGraphArcList(G, 5);
kpeter@374
   134
kpeter@374
   135
  // Check changeSource() and changeTarget()
kpeter@374
   136
  G.changeTarget(a4, n1);
kpeter@374
   137
kpeter@374
   138
  checkGraphNodeList(G, 4);
kpeter@374
   139
  checkGraphArcList(G, 5);
kpeter@374
   140
kpeter@374
   141
  checkGraphOutArcList(G, n1, 1);
kpeter@374
   142
  checkGraphOutArcList(G, n2, 1);
kpeter@374
   143
  checkGraphOutArcList(G, n3, 0);
kpeter@374
   144
  checkGraphOutArcList(G, n4, 3);
kpeter@374
   145
kpeter@374
   146
  checkGraphInArcList(G, n1, 2);
kpeter@374
   147
  checkGraphInArcList(G, n2, 1);
kpeter@374
   148
  checkGraphInArcList(G, n3, 1);
kpeter@374
   149
  checkGraphInArcList(G, n4, 1);
kpeter@374
   150
kpeter@374
   151
  checkGraphConArcList(G, 5);
kpeter@374
   152
kpeter@374
   153
  G.changeSource(a4, n3);
kpeter@374
   154
kpeter@374
   155
  checkGraphNodeList(G, 4);
kpeter@374
   156
  checkGraphArcList(G, 5);
kpeter@374
   157
kpeter@374
   158
  checkGraphOutArcList(G, n1, 1);
kpeter@374
   159
  checkGraphOutArcList(G, n2, 1);
kpeter@374
   160
  checkGraphOutArcList(G, n3, 1);
kpeter@374
   161
  checkGraphOutArcList(G, n4, 2);
kpeter@374
   162
kpeter@374
   163
  checkGraphInArcList(G, n1, 2);
kpeter@374
   164
  checkGraphInArcList(G, n2, 1);
kpeter@374
   165
  checkGraphInArcList(G, n3, 1);
kpeter@374
   166
  checkGraphInArcList(G, n4, 1);
kpeter@374
   167
kpeter@374
   168
  checkGraphConArcList(G, 5);
kpeter@374
   169
kpeter@374
   170
  // Check contract()
kpeter@374
   171
  G.contract(n2, n4, false);
kpeter@374
   172
kpeter@374
   173
  checkGraphNodeList(G, 3);
kpeter@374
   174
  checkGraphArcList(G, 5);
kpeter@374
   175
kpeter@374
   176
  checkGraphOutArcList(G, n1, 1);
kpeter@374
   177
  checkGraphOutArcList(G, n2, 3);
kpeter@374
   178
  checkGraphOutArcList(G, n3, 1);
kpeter@374
   179
kpeter@374
   180
  checkGraphInArcList(G, n1, 2);
kpeter@374
   181
  checkGraphInArcList(G, n2, 2);
kpeter@374
   182
  checkGraphInArcList(G, n3, 1);
kpeter@374
   183
kpeter@374
   184
  checkGraphConArcList(G, 5);
kpeter@374
   185
kpeter@374
   186
  G.contract(n2, n1);
kpeter@374
   187
kpeter@374
   188
  checkGraphNodeList(G, 2);
kpeter@374
   189
  checkGraphArcList(G, 3);
kpeter@374
   190
kpeter@374
   191
  checkGraphOutArcList(G, n2, 2);
kpeter@374
   192
  checkGraphOutArcList(G, n3, 1);
kpeter@374
   193
kpeter@374
   194
  checkGraphInArcList(G, n2, 2);
kpeter@374
   195
  checkGraphInArcList(G, n3, 1);
kpeter@374
   196
kpeter@374
   197
  checkGraphConArcList(G, 3);
kpeter@374
   198
}
kpeter@374
   199
kpeter@374
   200
template <class Digraph>
kpeter@374
   201
void checkDigraphErase() {
kpeter@374
   202
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@374
   203
kpeter@374
   204
  Digraph G;
kpeter@374
   205
  Node n1 = G.addNode(), n2 = G.addNode(),
kpeter@374
   206
       n3 = G.addNode(), n4 = G.addNode();
kpeter@374
   207
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1),
kpeter@374
   208
      a3 = G.addArc(n4, n3), a4 = G.addArc(n3, n1),
kpeter@374
   209
      a5 = G.addArc(n2, n4);
alpar@997
   210
  ignore_unused_variable_warning(a2,a3,a4,a5);
kpeter@374
   211
kpeter@374
   212
  // Check arc deletion
kpeter@374
   213
  G.erase(a1);
kpeter@374
   214
kpeter@374
   215
  checkGraphNodeList(G, 4);
kpeter@374
   216
  checkGraphArcList(G, 4);
kpeter@374
   217
kpeter@374
   218
  checkGraphOutArcList(G, n1, 0);
kpeter@374
   219
  checkGraphOutArcList(G, n2, 1);
kpeter@374
   220
  checkGraphOutArcList(G, n3, 1);
kpeter@374
   221
  checkGraphOutArcList(G, n4, 2);
kpeter@374
   222
kpeter@374
   223
  checkGraphInArcList(G, n1, 2);
kpeter@374
   224
  checkGraphInArcList(G, n2, 0);
kpeter@374
   225
  checkGraphInArcList(G, n3, 1);
kpeter@374
   226
  checkGraphInArcList(G, n4, 1);
kpeter@374
   227
kpeter@374
   228
  checkGraphConArcList(G, 4);
kpeter@374
   229
kpeter@374
   230
  // Check node deletion
kpeter@374
   231
  G.erase(n4);
kpeter@374
   232
kpeter@374
   233
  checkGraphNodeList(G, 3);
kpeter@374
   234
  checkGraphArcList(G, 1);
kpeter@374
   235
kpeter@374
   236
  checkGraphOutArcList(G, n1, 0);
kpeter@374
   237
  checkGraphOutArcList(G, n2, 0);
kpeter@374
   238
  checkGraphOutArcList(G, n3, 1);
kpeter@374
   239
  checkGraphOutArcList(G, n4, 0);
kpeter@374
   240
kpeter@374
   241
  checkGraphInArcList(G, n1, 1);
kpeter@374
   242
  checkGraphInArcList(G, n2, 0);
kpeter@374
   243
  checkGraphInArcList(G, n3, 0);
kpeter@374
   244
  checkGraphInArcList(G, n4, 0);
kpeter@374
   245
kpeter@374
   246
  checkGraphConArcList(G, 1);
kpeter@374
   247
}
kpeter@374
   248
kpeter@374
   249
kpeter@374
   250
template <class Digraph>
kpeter@374
   251
void checkDigraphSnapshot() {
kpeter@374
   252
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@374
   253
kpeter@374
   254
  Digraph G;
kpeter@374
   255
  Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
kpeter@374
   256
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
kpeter@374
   257
      a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
alpar@997
   258
  ignore_unused_variable_warning(a1,a2,a3,a4);
kpeter@374
   259
kpeter@374
   260
  typename Digraph::Snapshot snapshot(G);
kpeter@374
   261
kpeter@374
   262
  Node n = G.addNode();
kpeter@374
   263
  G.addArc(n3, n);
kpeter@374
   264
  G.addArc(n, n3);
kpeter@374
   265
kpeter@374
   266
  checkGraphNodeList(G, 4);
kpeter@374
   267
  checkGraphArcList(G, 6);
kpeter@374
   268
kpeter@374
   269
  snapshot.restore();
kpeter@374
   270
deba@228
   271
  checkGraphNodeList(G, 3);
deba@228
   272
  checkGraphArcList(G, 4);
deba@228
   273
deba@228
   274
  checkGraphOutArcList(G, n1, 1);
deba@228
   275
  checkGraphOutArcList(G, n2, 3);
deba@228
   276
  checkGraphOutArcList(G, n3, 0);
deba@228
   277
deba@228
   278
  checkGraphInArcList(G, n1, 1);
deba@228
   279
  checkGraphInArcList(G, n2, 1);
deba@228
   280
  checkGraphInArcList(G, n3, 2);
deba@228
   281
deba@228
   282
  checkGraphConArcList(G, 4);
deba@228
   283
deba@228
   284
  checkNodeIds(G);
deba@228
   285
  checkArcIds(G);
deba@228
   286
  checkGraphNodeMap(G);
deba@228
   287
  checkGraphArcMap(G);
deba@228
   288
kpeter@374
   289
  G.addNode();
kpeter@374
   290
  snapshot.save(G);
kpeter@374
   291
kpeter@374
   292
  G.addArc(G.addNode(), G.addNode());
kpeter@374
   293
kpeter@374
   294
  snapshot.restore();
kpeter@740
   295
  snapshot.save(G);
kpeter@740
   296
kpeter@740
   297
  checkGraphNodeList(G, 4);
kpeter@740
   298
  checkGraphArcList(G, 4);
kpeter@740
   299
kpeter@740
   300
  G.addArc(G.addNode(), G.addNode());
kpeter@740
   301
kpeter@740
   302
  snapshot.restore();
kpeter@374
   303
kpeter@374
   304
  checkGraphNodeList(G, 4);
kpeter@374
   305
  checkGraphArcList(G, 4);
deba@228
   306
}
deba@228
   307
deba@228
   308
void checkConcepts() {
kpeter@171
   309
  { // Checking digraph components
deba@57
   310
    checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
deba@57
   311
alpar@209
   312
    checkConcept<IDableDigraphComponent<>,
deba@57
   313
      IDableDigraphComponent<> >();
deba@57
   314
alpar@209
   315
    checkConcept<IterableDigraphComponent<>,
deba@57
   316
      IterableDigraphComponent<> >();
deba@57
   317
alpar@209
   318
    checkConcept<MappableDigraphComponent<>,
deba@57
   319
      MappableDigraphComponent<> >();
deba@57
   320
  }
kpeter@171
   321
  { // Checking skeleton digraph
deba@57
   322
    checkConcept<Digraph, Digraph>();
deba@57
   323
  }
kpeter@171
   324
  { // Checking ListDigraph
kpeter@171
   325
    checkConcept<Digraph, ListDigraph>();
deba@57
   326
    checkConcept<AlterableDigraphComponent<>, ListDigraph>();
deba@57
   327
    checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
deba@57
   328
    checkConcept<ClearableDigraphComponent<>, ListDigraph>();
deba@57
   329
    checkConcept<ErasableDigraphComponent<>, ListDigraph>();
kpeter@171
   330
  }
kpeter@171
   331
  { // Checking SmartDigraph
kpeter@171
   332
    checkConcept<Digraph, SmartDigraph>();
kpeter@171
   333
    checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
kpeter@171
   334
    checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
kpeter@171
   335
    checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
kpeter@171
   336
  }
kpeter@774
   337
  { // Checking StaticDigraph
kpeter@774
   338
    checkConcept<Digraph, StaticDigraph>();
kpeter@774
   339
    checkConcept<ClearableDigraphComponent<>, StaticDigraph>();
kpeter@774
   340
  }
kpeter@354
   341
  { // Checking FullDigraph
kpeter@354
   342
    checkConcept<Digraph, FullDigraph>();
kpeter@354
   343
  }
kpeter@171
   344
}
deba@57
   345
kpeter@171
   346
template <typename Digraph>
deba@228
   347
void checkDigraphValidity() {
kpeter@171
   348
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@171
   349
  Digraph g;
kpeter@171
   350
kpeter@171
   351
  Node
kpeter@171
   352
    n1 = g.addNode(),
kpeter@171
   353
    n2 = g.addNode(),
kpeter@171
   354
    n3 = g.addNode();
kpeter@171
   355
kpeter@171
   356
  Arc
kpeter@171
   357
    e1 = g.addArc(n1, n2),
kpeter@171
   358
    e2 = g.addArc(n2, n3);
alpar@997
   359
  ignore_unused_variable_warning(e2);
kpeter@171
   360
kpeter@171
   361
  check(g.valid(n1), "Wrong validity check");
kpeter@171
   362
  check(g.valid(e1), "Wrong validity check");
kpeter@171
   363
kpeter@171
   364
  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
kpeter@171
   365
  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
kpeter@171
   366
}
kpeter@171
   367
kpeter@171
   368
template <typename Digraph>
deba@228
   369
void checkDigraphValidityErase() {
kpeter@171
   370
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@171
   371
  Digraph g;
kpeter@171
   372
kpeter@171
   373
  Node
kpeter@171
   374
    n1 = g.addNode(),
kpeter@171
   375
    n2 = g.addNode(),
kpeter@171
   376
    n3 = g.addNode();
kpeter@171
   377
kpeter@171
   378
  Arc
kpeter@171
   379
    e1 = g.addArc(n1, n2),
kpeter@171
   380
    e2 = g.addArc(n2, n3);
kpeter@171
   381
kpeter@171
   382
  check(g.valid(n1), "Wrong validity check");
kpeter@171
   383
  check(g.valid(e1), "Wrong validity check");
kpeter@171
   384
kpeter@171
   385
  g.erase(n1);
kpeter@171
   386
kpeter@171
   387
  check(!g.valid(n1), "Wrong validity check");
kpeter@171
   388
  check(g.valid(n2), "Wrong validity check");
kpeter@171
   389
  check(g.valid(n3), "Wrong validity check");
kpeter@171
   390
  check(!g.valid(e1), "Wrong validity check");
kpeter@171
   391
  check(g.valid(e2), "Wrong validity check");
kpeter@171
   392
kpeter@171
   393
  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
kpeter@171
   394
  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
kpeter@171
   395
}
kpeter@171
   396
kpeter@774
   397
void checkStaticDigraph() {
kpeter@774
   398
  SmartDigraph g;
kpeter@774
   399
  SmartDigraph::NodeMap<StaticDigraph::Node> nref(g);
kpeter@774
   400
  SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g);
alpar@877
   401
kpeter@774
   402
  StaticDigraph G;
alpar@877
   403
kpeter@774
   404
  checkGraphNodeList(G, 0);
kpeter@774
   405
  checkGraphArcList(G, 0);
kpeter@774
   406
kpeter@774
   407
  G.build(g, nref, aref);
kpeter@774
   408
kpeter@774
   409
  checkGraphNodeList(G, 0);
kpeter@774
   410
  checkGraphArcList(G, 0);
kpeter@774
   411
kpeter@774
   412
  SmartDigraph::Node
kpeter@774
   413
    n1 = g.addNode(),
kpeter@774
   414
    n2 = g.addNode(),
kpeter@774
   415
    n3 = g.addNode();
kpeter@774
   416
kpeter@774
   417
  G.build(g, nref, aref);
kpeter@774
   418
kpeter@774
   419
  checkGraphNodeList(G, 3);
kpeter@774
   420
  checkGraphArcList(G, 0);
kpeter@774
   421
kpeter@774
   422
  SmartDigraph::Arc a1 = g.addArc(n1, n2);
kpeter@774
   423
kpeter@774
   424
  G.build(g, nref, aref);
kpeter@774
   425
kpeter@774
   426
  check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2],
kpeter@774
   427
        "Wrong arc or wrong references");
kpeter@774
   428
  checkGraphNodeList(G, 3);
kpeter@774
   429
  checkGraphArcList(G, 1);
kpeter@774
   430
kpeter@774
   431
  checkGraphOutArcList(G, nref[n1], 1);
kpeter@774
   432
  checkGraphOutArcList(G, nref[n2], 0);
kpeter@774
   433
  checkGraphOutArcList(G, nref[n3], 0);
kpeter@774
   434
kpeter@774
   435
  checkGraphInArcList(G, nref[n1], 0);
kpeter@774
   436
  checkGraphInArcList(G, nref[n2], 1);
kpeter@774
   437
  checkGraphInArcList(G, nref[n3], 0);
kpeter@774
   438
kpeter@774
   439
  checkGraphConArcList(G, 1);
kpeter@774
   440
kpeter@774
   441
  SmartDigraph::Arc
kpeter@774
   442
    a2 = g.addArc(n2, n1),
kpeter@774
   443
    a3 = g.addArc(n2, n3),
kpeter@774
   444
    a4 = g.addArc(n2, n3);
alpar@999
   445
  ignore_unused_variable_warning(a2,a3,a4);
kpeter@774
   446
kpeter@774
   447
  digraphCopy(g, G).nodeRef(nref).run();
kpeter@774
   448
kpeter@774
   449
  checkGraphNodeList(G, 3);
kpeter@774
   450
  checkGraphArcList(G, 4);
kpeter@774
   451
kpeter@774
   452
  checkGraphOutArcList(G, nref[n1], 1);
kpeter@774
   453
  checkGraphOutArcList(G, nref[n2], 3);
kpeter@774
   454
  checkGraphOutArcList(G, nref[n3], 0);
kpeter@774
   455
kpeter@774
   456
  checkGraphInArcList(G, nref[n1], 1);
kpeter@774
   457
  checkGraphInArcList(G, nref[n2], 1);
kpeter@774
   458
  checkGraphInArcList(G, nref[n3], 2);
kpeter@774
   459
kpeter@774
   460
  checkGraphConArcList(G, 4);
kpeter@774
   461
kpeter@777
   462
  std::vector<std::pair<int,int> > arcs;
kpeter@777
   463
  arcs.push_back(std::make_pair(0,1));
kpeter@777
   464
  arcs.push_back(std::make_pair(0,2));
kpeter@777
   465
  arcs.push_back(std::make_pair(1,3));
kpeter@777
   466
  arcs.push_back(std::make_pair(1,2));
kpeter@777
   467
  arcs.push_back(std::make_pair(3,0));
kpeter@777
   468
  arcs.push_back(std::make_pair(3,3));
kpeter@777
   469
  arcs.push_back(std::make_pair(4,2));
kpeter@777
   470
  arcs.push_back(std::make_pair(4,3));
kpeter@777
   471
  arcs.push_back(std::make_pair(4,1));
kpeter@777
   472
kpeter@777
   473
  G.build(6, arcs.begin(), arcs.end());
alpar@877
   474
kpeter@777
   475
  checkGraphNodeList(G, 6);
kpeter@777
   476
  checkGraphArcList(G, 9);
kpeter@777
   477
kpeter@777
   478
  checkGraphOutArcList(G, G.node(0), 2);
kpeter@777
   479
  checkGraphOutArcList(G, G.node(1), 2);
kpeter@777
   480
  checkGraphOutArcList(G, G.node(2), 0);
kpeter@777
   481
  checkGraphOutArcList(G, G.node(3), 2);
kpeter@777
   482
  checkGraphOutArcList(G, G.node(4), 3);
kpeter@777
   483
  checkGraphOutArcList(G, G.node(5), 0);
kpeter@777
   484
kpeter@777
   485
  checkGraphInArcList(G, G.node(0), 1);
kpeter@777
   486
  checkGraphInArcList(G, G.node(1), 2);
kpeter@777
   487
  checkGraphInArcList(G, G.node(2), 3);
kpeter@777
   488
  checkGraphInArcList(G, G.node(3), 3);
kpeter@777
   489
  checkGraphInArcList(G, G.node(4), 0);
kpeter@777
   490
  checkGraphInArcList(G, G.node(5), 0);
kpeter@777
   491
kpeter@777
   492
  checkGraphConArcList(G, 9);
kpeter@777
   493
kpeter@774
   494
  checkNodeIds(G);
kpeter@774
   495
  checkArcIds(G);
kpeter@774
   496
  checkGraphNodeMap(G);
kpeter@774
   497
  checkGraphArcMap(G);
alpar@877
   498
kpeter@776
   499
  int n = G.nodeNum();
kpeter@776
   500
  int m = G.arcNum();
kpeter@776
   501
  check(G.index(G.node(n-1)) == n-1, "Wrong index.");
kpeter@776
   502
  check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
kpeter@774
   503
}
kpeter@774
   504
alpar@375
   505
void checkFullDigraph(int num) {
alpar@375
   506
  typedef FullDigraph Digraph;
alpar@375
   507
  DIGRAPH_TYPEDEFS(Digraph);
kpeter@737
   508
alpar@375
   509
  Digraph G(num);
kpeter@737
   510
  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
kpeter@737
   511
kpeter@737
   512
  G.resize(num);
kpeter@737
   513
  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
alpar@375
   514
alpar@375
   515
  checkGraphNodeList(G, num);
alpar@375
   516
  checkGraphArcList(G, num * num);
alpar@375
   517
alpar@375
   518
  for (NodeIt n(G); n != INVALID; ++n) {
alpar@375
   519
    checkGraphOutArcList(G, n, num);
alpar@375
   520
    checkGraphInArcList(G, n, num);
alpar@375
   521
  }
alpar@375
   522
alpar@375
   523
  checkGraphConArcList(G, num * num);
alpar@375
   524
alpar@375
   525
  checkNodeIds(G);
alpar@375
   526
  checkArcIds(G);
alpar@375
   527
  checkGraphNodeMap(G);
alpar@375
   528
  checkGraphArcMap(G);
alpar@375
   529
alpar@375
   530
  for (int i = 0; i < G.nodeNum(); ++i) {
alpar@375
   531
    check(G.index(G(i)) == i, "Wrong index");
alpar@375
   532
  }
alpar@375
   533
alpar@375
   534
  for (NodeIt s(G); s != INVALID; ++s) {
alpar@375
   535
    for (NodeIt t(G); t != INVALID; ++t) {
alpar@375
   536
      Arc a = G.arc(s, t);
alpar@375
   537
      check(G.source(a) == s && G.target(a) == t, "Wrong arc lookup");
alpar@375
   538
    }
alpar@375
   539
  }
alpar@375
   540
}
alpar@375
   541
deba@228
   542
void checkDigraphs() {
kpeter@171
   543
  { // Checking ListDigraph
kpeter@374
   544
    checkDigraphBuild<ListDigraph>();
kpeter@374
   545
    checkDigraphSplit<ListDigraph>();
kpeter@374
   546
    checkDigraphAlter<ListDigraph>();
kpeter@374
   547
    checkDigraphErase<ListDigraph>();
kpeter@374
   548
    checkDigraphSnapshot<ListDigraph>();
deba@228
   549
    checkDigraphValidityErase<ListDigraph>();
deba@57
   550
  }
kpeter@171
   551
  { // Checking SmartDigraph
kpeter@374
   552
    checkDigraphBuild<SmartDigraph>();
kpeter@374
   553
    checkDigraphSplit<SmartDigraph>();
kpeter@374
   554
    checkDigraphSnapshot<SmartDigraph>();
deba@228
   555
    checkDigraphValidity<SmartDigraph>();
kpeter@171
   556
  }
kpeter@774
   557
  { // Checking StaticDigraph
kpeter@774
   558
    checkStaticDigraph();
kpeter@774
   559
  }
deba@353
   560
  { // Checking FullDigraph
deba@353
   561
    checkFullDigraph(8);
deba@353
   562
  }
kpeter@171
   563
}
deba@57
   564
kpeter@171
   565
int main() {
deba@228
   566
  checkDigraphs();
deba@228
   567
  checkConcepts();
deba@57
   568
  return 0;
deba@57
   569
}