test/digraph_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 18 Mar 2013 17:41:19 +0100
changeset 1221 1c978b5bcc65
parent 1159 7fdaa05a69a1
child 1259 8b2d4e5d96e4
permissions -rw-r--r--
Use doxygen's own bibtex support (#456)
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@956
     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@821
    22
#include <lemon/static_graph.h>
deba@365
    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@387
    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@783
    39
  G.reserveNode(3);
kpeter@783
    40
  G.reserveArc(4);
kpeter@783
    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@387
    64
  Arc a2 = G.addArc(n2, n1),
kpeter@387
    65
      a3 = G.addArc(n2, n3),
kpeter@387
    66
      a4 = G.addArc(n2, n3);
alpar@1157
    67
  ignore_unused_variable_warning(a2,a3,a4);
kpeter@387
    68
kpeter@387
    69
  checkGraphNodeList(G, 3);
kpeter@387
    70
  checkGraphArcList(G, 4);
kpeter@387
    71
kpeter@387
    72
  checkGraphOutArcList(G, n1, 1);
kpeter@387
    73
  checkGraphOutArcList(G, n2, 3);
kpeter@387
    74
  checkGraphOutArcList(G, n3, 0);
kpeter@387
    75
kpeter@387
    76
  checkGraphInArcList(G, n1, 1);
kpeter@387
    77
  checkGraphInArcList(G, n2, 1);
kpeter@387
    78
  checkGraphInArcList(G, n3, 2);
kpeter@387
    79
kpeter@387
    80
  checkGraphConArcList(G, 4);
kpeter@387
    81
kpeter@387
    82
  checkNodeIds(G);
kpeter@387
    83
  checkArcIds(G);
kpeter@387
    84
  checkGraphNodeMap(G);
kpeter@387
    85
  checkGraphArcMap(G);
kpeter@387
    86
}
kpeter@387
    87
kpeter@387
    88
template <class Digraph>
kpeter@387
    89
void checkDigraphSplit() {
kpeter@387
    90
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@387
    91
kpeter@387
    92
  Digraph G;
kpeter@387
    93
  Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
kpeter@387
    94
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
kpeter@387
    95
      a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
alpar@1157
    96
  ignore_unused_variable_warning(a1,a2,a3,a4);
kpeter@387
    97
kpeter@387
    98
  Node n4 = G.split(n2);
kpeter@387
    99
kpeter@387
   100
  check(G.target(OutArcIt(G, n2)) == n4 &&
kpeter@387
   101
        G.source(InArcIt(G, n4)) == n2,
kpeter@387
   102
        "Wrong split.");
kpeter@387
   103
kpeter@387
   104
  checkGraphNodeList(G, 4);
kpeter@387
   105
  checkGraphArcList(G, 5);
kpeter@387
   106
kpeter@387
   107
  checkGraphOutArcList(G, n1, 1);
kpeter@387
   108
  checkGraphOutArcList(G, n2, 1);
kpeter@387
   109
  checkGraphOutArcList(G, n3, 0);
kpeter@387
   110
  checkGraphOutArcList(G, n4, 3);
kpeter@387
   111
kpeter@387
   112
  checkGraphInArcList(G, n1, 1);
kpeter@387
   113
  checkGraphInArcList(G, n2, 1);
kpeter@387
   114
  checkGraphInArcList(G, n3, 2);
kpeter@387
   115
  checkGraphInArcList(G, n4, 1);
kpeter@387
   116
kpeter@387
   117
  checkGraphConArcList(G, 5);
kpeter@387
   118
}
kpeter@387
   119
kpeter@387
   120
template <class Digraph>
kpeter@387
   121
void checkDigraphAlter() {
kpeter@387
   122
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@387
   123
kpeter@387
   124
  Digraph G;
kpeter@387
   125
  Node n1 = G.addNode(), n2 = G.addNode(),
kpeter@387
   126
       n3 = G.addNode(), n4 = G.addNode();
kpeter@387
   127
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1),
kpeter@387
   128
      a3 = G.addArc(n4, n3), a4 = G.addArc(n4, n3),
kpeter@387
   129
      a5 = G.addArc(n2, n4);
alpar@1157
   130
  ignore_unused_variable_warning(a1,a2,a3,a5);
kpeter@387
   131
kpeter@387
   132
  checkGraphNodeList(G, 4);
kpeter@387
   133
  checkGraphArcList(G, 5);
kpeter@387
   134
kpeter@387
   135
  // Check changeSource() and changeTarget()
kpeter@387
   136
  G.changeTarget(a4, n1);
kpeter@387
   137
kpeter@387
   138
  checkGraphNodeList(G, 4);
kpeter@387
   139
  checkGraphArcList(G, 5);
kpeter@387
   140
kpeter@387
   141
  checkGraphOutArcList(G, n1, 1);
kpeter@387
   142
  checkGraphOutArcList(G, n2, 1);
kpeter@387
   143
  checkGraphOutArcList(G, n3, 0);
kpeter@387
   144
  checkGraphOutArcList(G, n4, 3);
kpeter@387
   145
kpeter@387
   146
  checkGraphInArcList(G, n1, 2);
kpeter@387
   147
  checkGraphInArcList(G, n2, 1);
kpeter@387
   148
  checkGraphInArcList(G, n3, 1);
kpeter@387
   149
  checkGraphInArcList(G, n4, 1);
kpeter@387
   150
kpeter@387
   151
  checkGraphConArcList(G, 5);
kpeter@387
   152
kpeter@387
   153
  G.changeSource(a4, n3);
kpeter@387
   154
kpeter@387
   155
  checkGraphNodeList(G, 4);
kpeter@387
   156
  checkGraphArcList(G, 5);
kpeter@387
   157
kpeter@387
   158
  checkGraphOutArcList(G, n1, 1);
kpeter@387
   159
  checkGraphOutArcList(G, n2, 1);
kpeter@387
   160
  checkGraphOutArcList(G, n3, 1);
kpeter@387
   161
  checkGraphOutArcList(G, n4, 2);
kpeter@387
   162
kpeter@387
   163
  checkGraphInArcList(G, n1, 2);
kpeter@387
   164
  checkGraphInArcList(G, n2, 1);
kpeter@387
   165
  checkGraphInArcList(G, n3, 1);
kpeter@387
   166
  checkGraphInArcList(G, n4, 1);
kpeter@387
   167
kpeter@387
   168
  checkGraphConArcList(G, 5);
kpeter@387
   169
kpeter@387
   170
  // Check contract()
kpeter@387
   171
  G.contract(n2, n4, false);
kpeter@387
   172
kpeter@387
   173
  checkGraphNodeList(G, 3);
kpeter@387
   174
  checkGraphArcList(G, 5);
kpeter@387
   175
kpeter@387
   176
  checkGraphOutArcList(G, n1, 1);
kpeter@387
   177
  checkGraphOutArcList(G, n2, 3);
kpeter@387
   178
  checkGraphOutArcList(G, n3, 1);
kpeter@387
   179
kpeter@387
   180
  checkGraphInArcList(G, n1, 2);
kpeter@387
   181
  checkGraphInArcList(G, n2, 2);
kpeter@387
   182
  checkGraphInArcList(G, n3, 1);
kpeter@387
   183
kpeter@387
   184
  checkGraphConArcList(G, 5);
kpeter@387
   185
kpeter@387
   186
  G.contract(n2, n1);
kpeter@387
   187
kpeter@387
   188
  checkGraphNodeList(G, 2);
kpeter@387
   189
  checkGraphArcList(G, 3);
kpeter@387
   190
kpeter@387
   191
  checkGraphOutArcList(G, n2, 2);
kpeter@387
   192
  checkGraphOutArcList(G, n3, 1);
kpeter@387
   193
kpeter@387
   194
  checkGraphInArcList(G, n2, 2);
kpeter@387
   195
  checkGraphInArcList(G, n3, 1);
kpeter@387
   196
kpeter@387
   197
  checkGraphConArcList(G, 3);
kpeter@387
   198
}
kpeter@387
   199
kpeter@387
   200
template <class Digraph>
kpeter@387
   201
void checkDigraphErase() {
kpeter@387
   202
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@387
   203
kpeter@387
   204
  Digraph G;
kpeter@387
   205
  Node n1 = G.addNode(), n2 = G.addNode(),
kpeter@387
   206
       n3 = G.addNode(), n4 = G.addNode();
kpeter@387
   207
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1),
kpeter@387
   208
      a3 = G.addArc(n4, n3), a4 = G.addArc(n3, n1),
kpeter@387
   209
      a5 = G.addArc(n2, n4);
alpar@1157
   210
  ignore_unused_variable_warning(a2,a3,a4,a5);
kpeter@387
   211
kpeter@387
   212
  // Check arc deletion
kpeter@387
   213
  G.erase(a1);
kpeter@387
   214
kpeter@387
   215
  checkGraphNodeList(G, 4);
kpeter@387
   216
  checkGraphArcList(G, 4);
kpeter@387
   217
kpeter@387
   218
  checkGraphOutArcList(G, n1, 0);
kpeter@387
   219
  checkGraphOutArcList(G, n2, 1);
kpeter@387
   220
  checkGraphOutArcList(G, n3, 1);
kpeter@387
   221
  checkGraphOutArcList(G, n4, 2);
kpeter@387
   222
kpeter@387
   223
  checkGraphInArcList(G, n1, 2);
kpeter@387
   224
  checkGraphInArcList(G, n2, 0);
kpeter@387
   225
  checkGraphInArcList(G, n3, 1);
kpeter@387
   226
  checkGraphInArcList(G, n4, 1);
kpeter@387
   227
kpeter@387
   228
  checkGraphConArcList(G, 4);
kpeter@387
   229
kpeter@387
   230
  // Check node deletion
kpeter@387
   231
  G.erase(n4);
kpeter@387
   232
kpeter@387
   233
  checkGraphNodeList(G, 3);
kpeter@387
   234
  checkGraphArcList(G, 1);
kpeter@387
   235
kpeter@387
   236
  checkGraphOutArcList(G, n1, 0);
kpeter@387
   237
  checkGraphOutArcList(G, n2, 0);
kpeter@387
   238
  checkGraphOutArcList(G, n3, 1);
kpeter@387
   239
  checkGraphOutArcList(G, n4, 0);
kpeter@387
   240
kpeter@387
   241
  checkGraphInArcList(G, n1, 1);
kpeter@387
   242
  checkGraphInArcList(G, n2, 0);
kpeter@387
   243
  checkGraphInArcList(G, n3, 0);
kpeter@387
   244
  checkGraphInArcList(G, n4, 0);
kpeter@387
   245
kpeter@387
   246
  checkGraphConArcList(G, 1);
kpeter@387
   247
}
kpeter@387
   248
kpeter@387
   249
kpeter@387
   250
template <class Digraph>
kpeter@387
   251
void checkDigraphSnapshot() {
kpeter@387
   252
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@387
   253
kpeter@387
   254
  Digraph G;
kpeter@387
   255
  Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
kpeter@387
   256
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
kpeter@387
   257
      a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
alpar@1157
   258
  ignore_unused_variable_warning(a1,a2,a3,a4);
kpeter@387
   259
kpeter@387
   260
  typename Digraph::Snapshot snapshot(G);
kpeter@387
   261
kpeter@387
   262
  Node n = G.addNode();
kpeter@387
   263
  G.addArc(n3, n);
kpeter@387
   264
  G.addArc(n, n3);
kpeter@387
   265
kpeter@387
   266
  checkGraphNodeList(G, 4);
kpeter@387
   267
  checkGraphArcList(G, 6);
kpeter@387
   268
kpeter@387
   269
  snapshot.restore();
kpeter@387
   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@387
   289
  G.addNode();
kpeter@387
   290
  snapshot.save(G);
kpeter@387
   291
kpeter@387
   292
  G.addArc(G.addNode(), G.addNode());
kpeter@387
   293
kpeter@387
   294
  snapshot.restore();
kpeter@787
   295
  snapshot.save(G);
kpeter@787
   296
kpeter@787
   297
  checkGraphNodeList(G, 4);
kpeter@787
   298
  checkGraphArcList(G, 4);
kpeter@787
   299
kpeter@787
   300
  G.addArc(G.addNode(), G.addNode());
kpeter@787
   301
kpeter@787
   302
  snapshot.restore();
kpeter@387
   303
kpeter@387
   304
  checkGraphNodeList(G, 4);
kpeter@387
   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@821
   337
  { // Checking StaticDigraph
kpeter@821
   338
    checkConcept<Digraph, StaticDigraph>();
kpeter@821
   339
    checkConcept<ClearableDigraphComponent<>, StaticDigraph>();
kpeter@821
   340
  }
kpeter@366
   341
  { // Checking FullDigraph
kpeter@366
   342
    checkConcept<Digraph, FullDigraph>();
kpeter@366
   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@1157
   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@821
   397
void checkStaticDigraph() {
kpeter@821
   398
  SmartDigraph g;
kpeter@821
   399
  SmartDigraph::NodeMap<StaticDigraph::Node> nref(g);
kpeter@821
   400
  SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g);
alpar@956
   401
kpeter@821
   402
  StaticDigraph G;
alpar@956
   403
kpeter@821
   404
  checkGraphNodeList(G, 0);
kpeter@821
   405
  checkGraphArcList(G, 0);
kpeter@821
   406
kpeter@821
   407
  G.build(g, nref, aref);
kpeter@821
   408
kpeter@821
   409
  checkGraphNodeList(G, 0);
kpeter@821
   410
  checkGraphArcList(G, 0);
kpeter@821
   411
kpeter@821
   412
  SmartDigraph::Node
kpeter@821
   413
    n1 = g.addNode(),
kpeter@821
   414
    n2 = g.addNode(),
kpeter@821
   415
    n3 = g.addNode();
kpeter@821
   416
kpeter@821
   417
  G.build(g, nref, aref);
kpeter@821
   418
kpeter@821
   419
  checkGraphNodeList(G, 3);
kpeter@821
   420
  checkGraphArcList(G, 0);
kpeter@821
   421
kpeter@821
   422
  SmartDigraph::Arc a1 = g.addArc(n1, n2);
kpeter@821
   423
kpeter@821
   424
  G.build(g, nref, aref);
kpeter@821
   425
kpeter@821
   426
  check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2],
kpeter@821
   427
        "Wrong arc or wrong references");
kpeter@821
   428
  checkGraphNodeList(G, 3);
kpeter@821
   429
  checkGraphArcList(G, 1);
kpeter@821
   430
kpeter@821
   431
  checkGraphOutArcList(G, nref[n1], 1);
kpeter@821
   432
  checkGraphOutArcList(G, nref[n2], 0);
kpeter@821
   433
  checkGraphOutArcList(G, nref[n3], 0);
kpeter@821
   434
kpeter@821
   435
  checkGraphInArcList(G, nref[n1], 0);
kpeter@821
   436
  checkGraphInArcList(G, nref[n2], 1);
kpeter@821
   437
  checkGraphInArcList(G, nref[n3], 0);
kpeter@821
   438
kpeter@821
   439
  checkGraphConArcList(G, 1);
kpeter@821
   440
kpeter@821
   441
  SmartDigraph::Arc
kpeter@821
   442
    a2 = g.addArc(n2, n1),
kpeter@821
   443
    a3 = g.addArc(n2, n3),
kpeter@821
   444
    a4 = g.addArc(n2, n3);
alpar@1160
   445
  ignore_unused_variable_warning(a2,a3,a4);
kpeter@821
   446
kpeter@821
   447
  digraphCopy(g, G).nodeRef(nref).run();
kpeter@821
   448
kpeter@821
   449
  checkGraphNodeList(G, 3);
kpeter@821
   450
  checkGraphArcList(G, 4);
kpeter@821
   451
kpeter@821
   452
  checkGraphOutArcList(G, nref[n1], 1);
kpeter@821
   453
  checkGraphOutArcList(G, nref[n2], 3);
kpeter@821
   454
  checkGraphOutArcList(G, nref[n3], 0);
kpeter@821
   455
kpeter@821
   456
  checkGraphInArcList(G, nref[n1], 1);
kpeter@821
   457
  checkGraphInArcList(G, nref[n2], 1);
kpeter@821
   458
  checkGraphInArcList(G, nref[n3], 2);
kpeter@821
   459
kpeter@821
   460
  checkGraphConArcList(G, 4);
kpeter@821
   461
kpeter@824
   462
  std::vector<std::pair<int,int> > arcs;
kpeter@824
   463
  arcs.push_back(std::make_pair(0,1));
kpeter@824
   464
  arcs.push_back(std::make_pair(0,2));
kpeter@824
   465
  arcs.push_back(std::make_pair(1,3));
kpeter@824
   466
  arcs.push_back(std::make_pair(1,2));
kpeter@824
   467
  arcs.push_back(std::make_pair(3,0));
kpeter@824
   468
  arcs.push_back(std::make_pair(3,3));
kpeter@824
   469
  arcs.push_back(std::make_pair(4,2));
kpeter@824
   470
  arcs.push_back(std::make_pair(4,3));
kpeter@824
   471
  arcs.push_back(std::make_pair(4,1));
kpeter@824
   472
kpeter@824
   473
  G.build(6, arcs.begin(), arcs.end());
alpar@956
   474
kpeter@824
   475
  checkGraphNodeList(G, 6);
kpeter@824
   476
  checkGraphArcList(G, 9);
kpeter@824
   477
kpeter@824
   478
  checkGraphOutArcList(G, G.node(0), 2);
kpeter@824
   479
  checkGraphOutArcList(G, G.node(1), 2);
kpeter@824
   480
  checkGraphOutArcList(G, G.node(2), 0);
kpeter@824
   481
  checkGraphOutArcList(G, G.node(3), 2);
kpeter@824
   482
  checkGraphOutArcList(G, G.node(4), 3);
kpeter@824
   483
  checkGraphOutArcList(G, G.node(5), 0);
kpeter@824
   484
kpeter@824
   485
  checkGraphInArcList(G, G.node(0), 1);
kpeter@824
   486
  checkGraphInArcList(G, G.node(1), 2);
kpeter@824
   487
  checkGraphInArcList(G, G.node(2), 3);
kpeter@824
   488
  checkGraphInArcList(G, G.node(3), 3);
kpeter@824
   489
  checkGraphInArcList(G, G.node(4), 0);
kpeter@824
   490
  checkGraphInArcList(G, G.node(5), 0);
kpeter@824
   491
kpeter@824
   492
  checkGraphConArcList(G, 9);
kpeter@824
   493
kpeter@821
   494
  checkNodeIds(G);
kpeter@821
   495
  checkArcIds(G);
kpeter@821
   496
  checkGraphNodeMap(G);
kpeter@821
   497
  checkGraphArcMap(G);
alpar@956
   498
kpeter@823
   499
  int n = G.nodeNum();
kpeter@823
   500
  int m = G.arcNum();
kpeter@823
   501
  check(G.index(G.node(n-1)) == n-1, "Wrong index.");
kpeter@823
   502
  check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
kpeter@821
   503
}
kpeter@821
   504
alpar@388
   505
void checkFullDigraph(int num) {
alpar@388
   506
  typedef FullDigraph Digraph;
alpar@388
   507
  DIGRAPH_TYPEDEFS(Digraph);
kpeter@784
   508
alpar@388
   509
  Digraph G(num);
kpeter@784
   510
  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
kpeter@784
   511
kpeter@784
   512
  G.resize(num);
kpeter@784
   513
  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
alpar@388
   514
alpar@388
   515
  checkGraphNodeList(G, num);
alpar@388
   516
  checkGraphArcList(G, num * num);
alpar@388
   517
alpar@388
   518
  for (NodeIt n(G); n != INVALID; ++n) {
alpar@388
   519
    checkGraphOutArcList(G, n, num);
alpar@388
   520
    checkGraphInArcList(G, n, num);
alpar@388
   521
  }
alpar@388
   522
alpar@388
   523
  checkGraphConArcList(G, num * num);
alpar@388
   524
alpar@388
   525
  checkNodeIds(G);
alpar@388
   526
  checkArcIds(G);
alpar@388
   527
  checkGraphNodeMap(G);
alpar@388
   528
  checkGraphArcMap(G);
alpar@388
   529
alpar@388
   530
  for (int i = 0; i < G.nodeNum(); ++i) {
alpar@388
   531
    check(G.index(G(i)) == i, "Wrong index");
alpar@388
   532
  }
alpar@388
   533
alpar@388
   534
  for (NodeIt s(G); s != INVALID; ++s) {
alpar@388
   535
    for (NodeIt t(G); t != INVALID; ++t) {
alpar@388
   536
      Arc a = G.arc(s, t);
alpar@388
   537
      check(G.source(a) == s && G.target(a) == t, "Wrong arc lookup");
alpar@388
   538
    }
alpar@388
   539
  }
alpar@388
   540
}
alpar@388
   541
deba@228
   542
void checkDigraphs() {
kpeter@171
   543
  { // Checking ListDigraph
kpeter@387
   544
    checkDigraphBuild<ListDigraph>();
kpeter@387
   545
    checkDigraphSplit<ListDigraph>();
kpeter@387
   546
    checkDigraphAlter<ListDigraph>();
kpeter@387
   547
    checkDigraphErase<ListDigraph>();
kpeter@387
   548
    checkDigraphSnapshot<ListDigraph>();
deba@228
   549
    checkDigraphValidityErase<ListDigraph>();
deba@57
   550
  }
kpeter@171
   551
  { // Checking SmartDigraph
kpeter@387
   552
    checkDigraphBuild<SmartDigraph>();
kpeter@387
   553
    checkDigraphSplit<SmartDigraph>();
kpeter@387
   554
    checkDigraphSnapshot<SmartDigraph>();
deba@228
   555
    checkDigraphValidity<SmartDigraph>();
kpeter@171
   556
  }
kpeter@821
   557
  { // Checking StaticDigraph
kpeter@821
   558
    checkStaticDigraph();
kpeter@821
   559
  }
deba@365
   560
  { // Checking FullDigraph
deba@365
   561
    checkFullDigraph(8);
deba@365
   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
}