test/edge_set_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Sat, 20 Mar 2010 11:03:12 +0100
changeset 1043 1bafdbd2fc46
parent 877 141f9c0db4a3
parent 997 761fe0846f49
child 1084 8b2d4e5d96e4
permissions -rw-r--r--
More tests for radixSort() (#362)
deba@468
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@468
     2
 *
deba@468
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@468
     4
 *
alpar@877
     5
 * Copyright (C) 2003-2010
deba@468
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@468
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@468
     8
 *
deba@468
     9
 * Permission to use, modify and distribute this software is granted
deba@468
    10
 * provided that this copyright notice appears in all copies. For
deba@468
    11
 * precise terms see the accompanying LICENSE file.
deba@468
    12
 *
deba@468
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@468
    14
 * express or implied, and with no claim as to its suitability for any
deba@468
    15
 * purpose.
deba@468
    16
 *
deba@468
    17
 */
deba@468
    18
deba@468
    19
#include <iostream>
deba@468
    20
#include <vector>
deba@468
    21
deba@468
    22
#include <lemon/concepts/digraph.h>
deba@468
    23
#include <lemon/concepts/graph.h>
deba@468
    24
#include <lemon/concept_check.h>
deba@468
    25
deba@468
    26
#include <lemon/list_graph.h>
deba@468
    27
deba@468
    28
#include <lemon/edge_set.h>
deba@468
    29
deba@468
    30
#include "graph_test.h"
deba@468
    31
#include "test_tools.h"
deba@468
    32
deba@468
    33
using namespace lemon;
deba@468
    34
deba@468
    35
void checkSmartArcSet() {
deba@488
    36
  checkConcept<concepts::Digraph, SmartArcSet<ListDigraph> >();
deba@468
    37
deba@468
    38
  typedef ListDigraph Digraph;
deba@468
    39
  typedef SmartArcSet<Digraph> ArcSet;
deba@468
    40
deba@468
    41
  Digraph digraph;
deba@468
    42
  Digraph::Node
deba@468
    43
    n1 = digraph.addNode(),
deba@468
    44
    n2 = digraph.addNode();
deba@468
    45
deba@468
    46
  Digraph::Arc ga1 = digraph.addArc(n1, n2);
alpar@997
    47
  ignore_unused_variable_warning(ga1);
deba@468
    48
deba@468
    49
  ArcSet arc_set(digraph);
deba@468
    50
deba@468
    51
  Digraph::Arc ga2 = digraph.addArc(n2, n1);
alpar@997
    52
  ignore_unused_variable_warning(ga2);
deba@468
    53
deba@468
    54
  checkGraphNodeList(arc_set, 2);
deba@468
    55
  checkGraphArcList(arc_set, 0);
deba@468
    56
deba@468
    57
  Digraph::Node
deba@468
    58
    n3 = digraph.addNode();
deba@468
    59
  checkGraphNodeList(arc_set, 3);
deba@468
    60
  checkGraphArcList(arc_set, 0);
deba@468
    61
deba@468
    62
  ArcSet::Arc a1 = arc_set.addArc(n1, n2);
deba@468
    63
  check(arc_set.source(a1) == n1 && arc_set.target(a1) == n2, "Wrong arc");
deba@468
    64
  checkGraphNodeList(arc_set, 3);
deba@468
    65
  checkGraphArcList(arc_set, 1);
deba@468
    66
deba@468
    67
  checkGraphOutArcList(arc_set, n1, 1);
deba@468
    68
  checkGraphOutArcList(arc_set, n2, 0);
deba@468
    69
  checkGraphOutArcList(arc_set, n3, 0);
deba@468
    70
deba@468
    71
  checkGraphInArcList(arc_set, n1, 0);
deba@468
    72
  checkGraphInArcList(arc_set, n2, 1);
deba@468
    73
  checkGraphInArcList(arc_set, n3, 0);
deba@468
    74
deba@468
    75
  checkGraphConArcList(arc_set, 1);
deba@468
    76
deba@468
    77
  ArcSet::Arc a2 = arc_set.addArc(n2, n1),
deba@468
    78
    a3 = arc_set.addArc(n2, n3),
deba@468
    79
    a4 = arc_set.addArc(n2, n3);
alpar@997
    80
  ignore_unused_variable_warning(a2,a3,a4);
alpar@997
    81
deba@468
    82
  checkGraphNodeList(arc_set, 3);
deba@468
    83
  checkGraphArcList(arc_set, 4);
deba@468
    84
deba@468
    85
  checkGraphOutArcList(arc_set, n1, 1);
deba@468
    86
  checkGraphOutArcList(arc_set, n2, 3);
deba@468
    87
  checkGraphOutArcList(arc_set, n3, 0);
deba@468
    88
deba@468
    89
  checkGraphInArcList(arc_set, n1, 1);
deba@468
    90
  checkGraphInArcList(arc_set, n2, 1);
deba@468
    91
  checkGraphInArcList(arc_set, n3, 2);
deba@468
    92
deba@468
    93
  checkGraphConArcList(arc_set, 4);
deba@468
    94
deba@468
    95
  checkNodeIds(arc_set);
deba@468
    96
  checkArcIds(arc_set);
deba@468
    97
  checkGraphNodeMap(arc_set);
deba@468
    98
  checkGraphArcMap(arc_set);
deba@468
    99
deba@468
   100
  check(arc_set.valid(), "Wrong validity");
deba@468
   101
  digraph.erase(n1);
deba@468
   102
  check(!arc_set.valid(), "Wrong validity");
deba@468
   103
}
deba@468
   104
deba@468
   105
void checkListArcSet() {
deba@488
   106
  checkConcept<concepts::Digraph, SmartArcSet<ListDigraph> >();
deba@468
   107
deba@468
   108
  typedef ListDigraph Digraph;
deba@468
   109
  typedef ListArcSet<Digraph> ArcSet;
deba@468
   110
deba@468
   111
  Digraph digraph;
deba@468
   112
  Digraph::Node
deba@468
   113
    n1 = digraph.addNode(),
deba@468
   114
    n2 = digraph.addNode();
deba@468
   115
deba@468
   116
  Digraph::Arc ga1 = digraph.addArc(n1, n2);
alpar@997
   117
  ignore_unused_variable_warning(ga1);
deba@468
   118
deba@468
   119
  ArcSet arc_set(digraph);
deba@468
   120
deba@468
   121
  Digraph::Arc ga2 = digraph.addArc(n2, n1);
alpar@997
   122
  ignore_unused_variable_warning(ga2);
deba@468
   123
deba@468
   124
  checkGraphNodeList(arc_set, 2);
deba@468
   125
  checkGraphArcList(arc_set, 0);
deba@468
   126
deba@468
   127
  Digraph::Node
deba@468
   128
    n3 = digraph.addNode();
deba@468
   129
  checkGraphNodeList(arc_set, 3);
deba@468
   130
  checkGraphArcList(arc_set, 0);
deba@468
   131
deba@468
   132
  ArcSet::Arc a1 = arc_set.addArc(n1, n2);
deba@468
   133
  check(arc_set.source(a1) == n1 && arc_set.target(a1) == n2, "Wrong arc");
deba@468
   134
  checkGraphNodeList(arc_set, 3);
deba@468
   135
  checkGraphArcList(arc_set, 1);
deba@468
   136
deba@468
   137
  checkGraphOutArcList(arc_set, n1, 1);
deba@468
   138
  checkGraphOutArcList(arc_set, n2, 0);
deba@468
   139
  checkGraphOutArcList(arc_set, n3, 0);
deba@468
   140
deba@468
   141
  checkGraphInArcList(arc_set, n1, 0);
deba@468
   142
  checkGraphInArcList(arc_set, n2, 1);
deba@468
   143
  checkGraphInArcList(arc_set, n3, 0);
deba@468
   144
deba@468
   145
  checkGraphConArcList(arc_set, 1);
deba@468
   146
deba@468
   147
  ArcSet::Arc a2 = arc_set.addArc(n2, n1),
deba@468
   148
    a3 = arc_set.addArc(n2, n3),
deba@468
   149
    a4 = arc_set.addArc(n2, n3);
alpar@997
   150
  ignore_unused_variable_warning(a2,a3,a4);
alpar@997
   151
deba@468
   152
  checkGraphNodeList(arc_set, 3);
deba@468
   153
  checkGraphArcList(arc_set, 4);
deba@468
   154
deba@468
   155
  checkGraphOutArcList(arc_set, n1, 1);
deba@468
   156
  checkGraphOutArcList(arc_set, n2, 3);
deba@468
   157
  checkGraphOutArcList(arc_set, n3, 0);
deba@468
   158
deba@468
   159
  checkGraphInArcList(arc_set, n1, 1);
deba@468
   160
  checkGraphInArcList(arc_set, n2, 1);
deba@468
   161
  checkGraphInArcList(arc_set, n3, 2);
deba@468
   162
deba@468
   163
  checkGraphConArcList(arc_set, 4);
deba@468
   164
deba@468
   165
  checkNodeIds(arc_set);
deba@468
   166
  checkArcIds(arc_set);
deba@468
   167
  checkGraphNodeMap(arc_set);
deba@468
   168
  checkGraphArcMap(arc_set);
deba@468
   169
deba@468
   170
  digraph.erase(n1);
deba@468
   171
deba@468
   172
  checkGraphNodeList(arc_set, 2);
deba@468
   173
  checkGraphArcList(arc_set, 2);
deba@468
   174
deba@468
   175
  checkGraphOutArcList(arc_set, n2, 2);
deba@468
   176
  checkGraphOutArcList(arc_set, n3, 0);
deba@468
   177
deba@468
   178
  checkGraphInArcList(arc_set, n2, 0);
deba@468
   179
  checkGraphInArcList(arc_set, n3, 2);
deba@468
   180
deba@468
   181
  checkNodeIds(arc_set);
deba@468
   182
  checkArcIds(arc_set);
deba@468
   183
  checkGraphNodeMap(arc_set);
deba@468
   184
  checkGraphArcMap(arc_set);
deba@468
   185
deba@468
   186
  checkGraphConArcList(arc_set, 2);
deba@468
   187
}
deba@468
   188
deba@468
   189
void checkSmartEdgeSet() {
deba@488
   190
  checkConcept<concepts::Digraph, SmartEdgeSet<ListDigraph> >();
deba@468
   191
deba@468
   192
  typedef ListDigraph Digraph;
deba@468
   193
  typedef SmartEdgeSet<Digraph> EdgeSet;
deba@468
   194
deba@468
   195
  Digraph digraph;
deba@468
   196
  Digraph::Node
deba@468
   197
    n1 = digraph.addNode(),
deba@468
   198
    n2 = digraph.addNode();
deba@468
   199
deba@468
   200
  Digraph::Arc ga1 = digraph.addArc(n1, n2);
alpar@997
   201
  ignore_unused_variable_warning(ga1);
deba@468
   202
deba@468
   203
  EdgeSet edge_set(digraph);
deba@468
   204
deba@468
   205
  Digraph::Arc ga2 = digraph.addArc(n2, n1);
alpar@997
   206
  ignore_unused_variable_warning(ga2);
deba@468
   207
deba@468
   208
  checkGraphNodeList(edge_set, 2);
deba@468
   209
  checkGraphArcList(edge_set, 0);
deba@468
   210
  checkGraphEdgeList(edge_set, 0);
deba@468
   211
deba@468
   212
  Digraph::Node
deba@468
   213
    n3 = digraph.addNode();
deba@468
   214
  checkGraphNodeList(edge_set, 3);
deba@468
   215
  checkGraphArcList(edge_set, 0);
deba@468
   216
  checkGraphEdgeList(edge_set, 0);
deba@468
   217
deba@468
   218
  EdgeSet::Edge e1 = edge_set.addEdge(n1, n2);
deba@468
   219
  check((edge_set.u(e1) == n1 && edge_set.v(e1) == n2) ||
deba@468
   220
        (edge_set.v(e1) == n1 && edge_set.u(e1) == n2), "Wrong edge");
deba@468
   221
  checkGraphNodeList(edge_set, 3);
deba@468
   222
  checkGraphArcList(edge_set, 2);
deba@468
   223
  checkGraphEdgeList(edge_set, 1);
deba@468
   224
deba@468
   225
  checkGraphOutArcList(edge_set, n1, 1);
deba@468
   226
  checkGraphOutArcList(edge_set, n2, 1);
deba@468
   227
  checkGraphOutArcList(edge_set, n3, 0);
deba@468
   228
deba@468
   229
  checkGraphInArcList(edge_set, n1, 1);
deba@468
   230
  checkGraphInArcList(edge_set, n2, 1);
deba@468
   231
  checkGraphInArcList(edge_set, n3, 0);
deba@468
   232
deba@468
   233
  checkGraphIncEdgeList(edge_set, n1, 1);
deba@468
   234
  checkGraphIncEdgeList(edge_set, n2, 1);
deba@468
   235
  checkGraphIncEdgeList(edge_set, n3, 0);
deba@468
   236
deba@468
   237
  checkGraphConEdgeList(edge_set, 1);
deba@468
   238
  checkGraphConArcList(edge_set, 2);
deba@468
   239
deba@468
   240
  EdgeSet::Edge e2 = edge_set.addEdge(n2, n1),
deba@468
   241
    e3 = edge_set.addEdge(n2, n3),
deba@468
   242
    e4 = edge_set.addEdge(n2, n3);
alpar@997
   243
  ignore_unused_variable_warning(e2,e3,e4);
alpar@997
   244
deba@468
   245
  checkGraphNodeList(edge_set, 3);
deba@468
   246
  checkGraphEdgeList(edge_set, 4);
deba@468
   247
deba@468
   248
  checkGraphOutArcList(edge_set, n1, 2);
deba@468
   249
  checkGraphOutArcList(edge_set, n2, 4);
deba@468
   250
  checkGraphOutArcList(edge_set, n3, 2);
deba@468
   251
deba@468
   252
  checkGraphInArcList(edge_set, n1, 2);
deba@468
   253
  checkGraphInArcList(edge_set, n2, 4);
deba@468
   254
  checkGraphInArcList(edge_set, n3, 2);
deba@468
   255
deba@468
   256
  checkGraphIncEdgeList(edge_set, n1, 2);
deba@468
   257
  checkGraphIncEdgeList(edge_set, n2, 4);
deba@468
   258
  checkGraphIncEdgeList(edge_set, n3, 2);
deba@468
   259
deba@468
   260
  checkGraphConEdgeList(edge_set, 4);
deba@468
   261
  checkGraphConArcList(edge_set, 8);
deba@468
   262
deba@468
   263
  checkArcDirections(edge_set);
deba@468
   264
deba@468
   265
  checkNodeIds(edge_set);
deba@468
   266
  checkArcIds(edge_set);
deba@468
   267
  checkEdgeIds(edge_set);
deba@468
   268
  checkGraphNodeMap(edge_set);
deba@468
   269
  checkGraphArcMap(edge_set);
deba@468
   270
  checkGraphEdgeMap(edge_set);
deba@468
   271
deba@468
   272
  check(edge_set.valid(), "Wrong validity");
deba@468
   273
  digraph.erase(n1);
deba@468
   274
  check(!edge_set.valid(), "Wrong validity");
deba@468
   275
}
deba@468
   276
deba@468
   277
void checkListEdgeSet() {
deba@488
   278
  checkConcept<concepts::Digraph, ListEdgeSet<ListDigraph> >();
deba@468
   279
deba@468
   280
  typedef ListDigraph Digraph;
deba@468
   281
  typedef ListEdgeSet<Digraph> EdgeSet;
deba@468
   282
deba@468
   283
  Digraph digraph;
deba@468
   284
  Digraph::Node
deba@468
   285
    n1 = digraph.addNode(),
deba@468
   286
    n2 = digraph.addNode();
deba@468
   287
deba@468
   288
  Digraph::Arc ga1 = digraph.addArc(n1, n2);
alpar@997
   289
  ignore_unused_variable_warning(ga1);
deba@468
   290
deba@468
   291
  EdgeSet edge_set(digraph);
deba@468
   292
deba@468
   293
  Digraph::Arc ga2 = digraph.addArc(n2, n1);
alpar@997
   294
  ignore_unused_variable_warning(ga2);
deba@468
   295
deba@468
   296
  checkGraphNodeList(edge_set, 2);
deba@468
   297
  checkGraphArcList(edge_set, 0);
deba@468
   298
  checkGraphEdgeList(edge_set, 0);
deba@468
   299
deba@468
   300
  Digraph::Node
deba@468
   301
    n3 = digraph.addNode();
deba@468
   302
  checkGraphNodeList(edge_set, 3);
deba@468
   303
  checkGraphArcList(edge_set, 0);
deba@468
   304
  checkGraphEdgeList(edge_set, 0);
deba@468
   305
deba@468
   306
  EdgeSet::Edge e1 = edge_set.addEdge(n1, n2);
deba@468
   307
  check((edge_set.u(e1) == n1 && edge_set.v(e1) == n2) ||
deba@468
   308
        (edge_set.v(e1) == n1 && edge_set.u(e1) == n2), "Wrong edge");
deba@468
   309
  checkGraphNodeList(edge_set, 3);
deba@468
   310
  checkGraphArcList(edge_set, 2);
deba@468
   311
  checkGraphEdgeList(edge_set, 1);
deba@468
   312
deba@468
   313
  checkGraphOutArcList(edge_set, n1, 1);
deba@468
   314
  checkGraphOutArcList(edge_set, n2, 1);
deba@468
   315
  checkGraphOutArcList(edge_set, n3, 0);
deba@468
   316
deba@468
   317
  checkGraphInArcList(edge_set, n1, 1);
deba@468
   318
  checkGraphInArcList(edge_set, n2, 1);
deba@468
   319
  checkGraphInArcList(edge_set, n3, 0);
deba@468
   320
deba@468
   321
  checkGraphIncEdgeList(edge_set, n1, 1);
deba@468
   322
  checkGraphIncEdgeList(edge_set, n2, 1);
deba@468
   323
  checkGraphIncEdgeList(edge_set, n3, 0);
deba@468
   324
deba@468
   325
  checkGraphConEdgeList(edge_set, 1);
deba@468
   326
  checkGraphConArcList(edge_set, 2);
deba@468
   327
deba@468
   328
  EdgeSet::Edge e2 = edge_set.addEdge(n2, n1),
deba@468
   329
    e3 = edge_set.addEdge(n2, n3),
deba@468
   330
    e4 = edge_set.addEdge(n2, n3);
alpar@997
   331
  ignore_unused_variable_warning(e2,e3,e4);
alpar@997
   332
deba@468
   333
  checkGraphNodeList(edge_set, 3);
deba@468
   334
  checkGraphEdgeList(edge_set, 4);
deba@468
   335
deba@468
   336
  checkGraphOutArcList(edge_set, n1, 2);
deba@468
   337
  checkGraphOutArcList(edge_set, n2, 4);
deba@468
   338
  checkGraphOutArcList(edge_set, n3, 2);
deba@468
   339
deba@468
   340
  checkGraphInArcList(edge_set, n1, 2);
deba@468
   341
  checkGraphInArcList(edge_set, n2, 4);
deba@468
   342
  checkGraphInArcList(edge_set, n3, 2);
deba@468
   343
deba@468
   344
  checkGraphIncEdgeList(edge_set, n1, 2);
deba@468
   345
  checkGraphIncEdgeList(edge_set, n2, 4);
deba@468
   346
  checkGraphIncEdgeList(edge_set, n3, 2);
deba@468
   347
deba@468
   348
  checkGraphConEdgeList(edge_set, 4);
deba@468
   349
  checkGraphConArcList(edge_set, 8);
deba@468
   350
deba@468
   351
  checkArcDirections(edge_set);
deba@468
   352
deba@468
   353
  checkNodeIds(edge_set);
deba@468
   354
  checkArcIds(edge_set);
deba@468
   355
  checkEdgeIds(edge_set);
deba@468
   356
  checkGraphNodeMap(edge_set);
deba@468
   357
  checkGraphArcMap(edge_set);
deba@468
   358
  checkGraphEdgeMap(edge_set);
deba@468
   359
deba@468
   360
  digraph.erase(n1);
deba@468
   361
deba@468
   362
  checkGraphNodeList(edge_set, 2);
deba@468
   363
  checkGraphArcList(edge_set, 4);
deba@468
   364
  checkGraphEdgeList(edge_set, 2);
deba@468
   365
deba@468
   366
  checkGraphOutArcList(edge_set, n2, 2);
deba@468
   367
  checkGraphOutArcList(edge_set, n3, 2);
deba@468
   368
deba@468
   369
  checkGraphInArcList(edge_set, n2, 2);
deba@468
   370
  checkGraphInArcList(edge_set, n3, 2);
deba@468
   371
deba@468
   372
  checkGraphIncEdgeList(edge_set, n2, 2);
deba@468
   373
  checkGraphIncEdgeList(edge_set, n3, 2);
deba@468
   374
deba@468
   375
  checkNodeIds(edge_set);
deba@468
   376
  checkArcIds(edge_set);
deba@468
   377
  checkEdgeIds(edge_set);
deba@468
   378
  checkGraphNodeMap(edge_set);
deba@468
   379
  checkGraphArcMap(edge_set);
deba@468
   380
  checkGraphEdgeMap(edge_set);
deba@468
   381
deba@468
   382
  checkGraphConEdgeList(edge_set, 2);
deba@468
   383
  checkGraphConArcList(edge_set, 4);
deba@468
   384
deba@468
   385
}
deba@468
   386
deba@468
   387
deba@468
   388
int main() {
deba@468
   389
deba@468
   390
  checkSmartArcSet();
deba@468
   391
  checkListArcSet();
deba@468
   392
  checkSmartEdgeSet();
deba@468
   393
  checkListEdgeSet();
deba@468
   394
deba@468
   395
  return 0;
deba@468
   396
}