test/digraph_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Fri, 26 Sep 2008 09:52:28 +0200
changeset 281 e9b4fbe163f5
parent 209 765619b7cbb2
child 365 37557a46e298
child 387 49d9a36b3b84
permissions -rw-r--r--
Merge
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@107
     5
 * Copyright (C) 2003-2008
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>
deba@57
    22
//#include <lemon/full_graph.h>
deba@57
    23
//#include <lemon/hypercube_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>
deba@228
    32
void checkDigraph() {
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
deba@228
    39
  Node
deba@228
    40
    n1 = G.addNode(),
deba@228
    41
    n2 = G.addNode(),
deba@228
    42
    n3 = G.addNode();
deba@228
    43
  checkGraphNodeList(G, 3);
deba@228
    44
  checkGraphArcList(G, 0);
deba@228
    45
deba@228
    46
  Arc a1 = G.addArc(n1, n2);
deba@228
    47
  check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc");
deba@228
    48
  checkGraphNodeList(G, 3);
deba@228
    49
  checkGraphArcList(G, 1);
deba@228
    50
deba@228
    51
  checkGraphOutArcList(G, n1, 1);
deba@228
    52
  checkGraphOutArcList(G, n2, 0);
deba@228
    53
  checkGraphOutArcList(G, n3, 0);
deba@228
    54
deba@228
    55
  checkGraphInArcList(G, n1, 0);
deba@228
    56
  checkGraphInArcList(G, n2, 1);
deba@228
    57
  checkGraphInArcList(G, n3, 0);
deba@228
    58
deba@228
    59
  checkGraphConArcList(G, 1);
deba@228
    60
deba@228
    61
  Arc a2 = G.addArc(n2, n1), a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
deba@228
    62
  checkGraphNodeList(G, 3);
deba@228
    63
  checkGraphArcList(G, 4);
deba@228
    64
deba@228
    65
  checkGraphOutArcList(G, n1, 1);
deba@228
    66
  checkGraphOutArcList(G, n2, 3);
deba@228
    67
  checkGraphOutArcList(G, n3, 0);
deba@228
    68
deba@228
    69
  checkGraphInArcList(G, n1, 1);
deba@228
    70
  checkGraphInArcList(G, n2, 1);
deba@228
    71
  checkGraphInArcList(G, n3, 2);
deba@228
    72
deba@228
    73
  checkGraphConArcList(G, 4);
deba@228
    74
deba@228
    75
  checkNodeIds(G);
deba@228
    76
  checkArcIds(G);
deba@228
    77
  checkGraphNodeMap(G);
deba@228
    78
  checkGraphArcMap(G);
deba@228
    79
deba@228
    80
}
deba@228
    81
deba@228
    82
deba@228
    83
void checkConcepts() {
kpeter@171
    84
  { // Checking digraph components
deba@57
    85
    checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
deba@57
    86
alpar@209
    87
    checkConcept<IDableDigraphComponent<>,
deba@57
    88
      IDableDigraphComponent<> >();
deba@57
    89
alpar@209
    90
    checkConcept<IterableDigraphComponent<>,
deba@57
    91
      IterableDigraphComponent<> >();
deba@57
    92
alpar@209
    93
    checkConcept<MappableDigraphComponent<>,
deba@57
    94
      MappableDigraphComponent<> >();
deba@57
    95
  }
kpeter@171
    96
  { // Checking skeleton digraph
deba@57
    97
    checkConcept<Digraph, Digraph>();
deba@57
    98
  }
kpeter@171
    99
  { // Checking ListDigraph
kpeter@171
   100
    checkConcept<Digraph, ListDigraph>();
deba@57
   101
    checkConcept<AlterableDigraphComponent<>, ListDigraph>();
deba@57
   102
    checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
deba@57
   103
    checkConcept<ClearableDigraphComponent<>, ListDigraph>();
deba@57
   104
    checkConcept<ErasableDigraphComponent<>, ListDigraph>();
kpeter@171
   105
  }
kpeter@171
   106
  { // Checking SmartDigraph
kpeter@171
   107
    checkConcept<Digraph, SmartDigraph>();
kpeter@171
   108
    checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
kpeter@171
   109
    checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
kpeter@171
   110
    checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
kpeter@171
   111
  }
kpeter@171
   112
//  { // Checking FullDigraph
kpeter@171
   113
//    checkConcept<Digraph, FullDigraph>();
kpeter@171
   114
//  }
kpeter@171
   115
//  { // Checking HyperCubeDigraph
kpeter@171
   116
//    checkConcept<Digraph, HyperCubeDigraph>();
kpeter@171
   117
//  }
kpeter@171
   118
}
deba@57
   119
kpeter@171
   120
template <typename Digraph>
deba@228
   121
void checkDigraphValidity() {
kpeter@171
   122
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@171
   123
  Digraph g;
kpeter@171
   124
kpeter@171
   125
  Node
kpeter@171
   126
    n1 = g.addNode(),
kpeter@171
   127
    n2 = g.addNode(),
kpeter@171
   128
    n3 = g.addNode();
kpeter@171
   129
kpeter@171
   130
  Arc
kpeter@171
   131
    e1 = g.addArc(n1, n2),
kpeter@171
   132
    e2 = g.addArc(n2, n3);
kpeter@171
   133
kpeter@171
   134
  check(g.valid(n1), "Wrong validity check");
kpeter@171
   135
  check(g.valid(e1), "Wrong validity check");
kpeter@171
   136
kpeter@171
   137
  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
kpeter@171
   138
  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
kpeter@171
   139
}
kpeter@171
   140
kpeter@171
   141
template <typename Digraph>
deba@228
   142
void checkDigraphValidityErase() {
kpeter@171
   143
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@171
   144
  Digraph g;
kpeter@171
   145
kpeter@171
   146
  Node
kpeter@171
   147
    n1 = g.addNode(),
kpeter@171
   148
    n2 = g.addNode(),
kpeter@171
   149
    n3 = g.addNode();
kpeter@171
   150
kpeter@171
   151
  Arc
kpeter@171
   152
    e1 = g.addArc(n1, n2),
kpeter@171
   153
    e2 = g.addArc(n2, n3);
kpeter@171
   154
kpeter@171
   155
  check(g.valid(n1), "Wrong validity check");
kpeter@171
   156
  check(g.valid(e1), "Wrong validity check");
kpeter@171
   157
kpeter@171
   158
  g.erase(n1);
kpeter@171
   159
kpeter@171
   160
  check(!g.valid(n1), "Wrong validity check");
kpeter@171
   161
  check(g.valid(n2), "Wrong validity check");
kpeter@171
   162
  check(g.valid(n3), "Wrong validity check");
kpeter@171
   163
  check(!g.valid(e1), "Wrong validity check");
kpeter@171
   164
  check(g.valid(e2), "Wrong validity check");
kpeter@171
   165
kpeter@171
   166
  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
kpeter@171
   167
  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
kpeter@171
   168
}
kpeter@171
   169
deba@228
   170
void checkDigraphs() {
kpeter@171
   171
  { // Checking ListDigraph
deba@57
   172
    checkDigraph<ListDigraph>();
deba@228
   173
    checkDigraphValidityErase<ListDigraph>();
deba@57
   174
  }
kpeter@171
   175
  { // Checking SmartDigraph
kpeter@171
   176
    checkDigraph<SmartDigraph>();
deba@228
   177
    checkDigraphValidity<SmartDigraph>();
kpeter@171
   178
  }
kpeter@171
   179
}
deba@57
   180
kpeter@171
   181
int main() {
deba@228
   182
  checkDigraphs();
deba@228
   183
  checkConcepts();
deba@57
   184
  return 0;
deba@57
   185
}