test/digraph_test.cc
author Peter Kovacs <kpeter@inf.elte.hu>
Sat, 05 Jul 2008 17:22:28 +0200
changeset 191 abc5b9d0c67e
parent 107 31a2e6d28f61
child 209 765619b7cbb2
permissions -rw-r--r--
lgf_demo.cc is merged with reader_writer_demo.cc (from SVN -r3501)
deba@57
     1
/* -*- C++ -*-
deba@57
     2
 *
deba@57
     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"
kpeter@171
    27
#include "graph_maps_test.h"
deba@57
    28
deba@57
    29
using namespace lemon;
deba@57
    30
using namespace lemon::concepts;
deba@57
    31
kpeter@171
    32
void check_concepts() {
kpeter@171
    33
  { // Checking digraph components
deba@57
    34
    checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
deba@57
    35
deba@57
    36
    checkConcept<IDableDigraphComponent<>, 
deba@57
    37
      IDableDigraphComponent<> >();
deba@57
    38
deba@57
    39
    checkConcept<IterableDigraphComponent<>, 
deba@57
    40
      IterableDigraphComponent<> >();
deba@57
    41
deba@57
    42
    checkConcept<MappableDigraphComponent<>, 
deba@57
    43
      MappableDigraphComponent<> >();
deba@57
    44
  }
kpeter@171
    45
  { // Checking skeleton digraph
deba@57
    46
    checkConcept<Digraph, Digraph>();
deba@57
    47
  }
kpeter@171
    48
  { // Checking ListDigraph
kpeter@171
    49
    checkConcept<Digraph, ListDigraph>();
deba@57
    50
    checkConcept<AlterableDigraphComponent<>, ListDigraph>();
deba@57
    51
    checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
deba@57
    52
    checkConcept<ClearableDigraphComponent<>, ListDigraph>();
deba@57
    53
    checkConcept<ErasableDigraphComponent<>, ListDigraph>();
kpeter@171
    54
    checkDigraphIterators<ListDigraph>();
kpeter@171
    55
  }
kpeter@171
    56
  { // Checking SmartDigraph
kpeter@171
    57
    checkConcept<Digraph, SmartDigraph>();
kpeter@171
    58
    checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
kpeter@171
    59
    checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
kpeter@171
    60
    checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
kpeter@171
    61
    checkDigraphIterators<SmartDigraph>();
kpeter@171
    62
  }
kpeter@171
    63
//  { // Checking FullDigraph
kpeter@171
    64
//    checkConcept<Digraph, FullDigraph>();
kpeter@171
    65
//    checkDigraphIterators<FullDigraph>();
kpeter@171
    66
//  }
kpeter@171
    67
//  { // Checking HyperCubeDigraph
kpeter@171
    68
//    checkConcept<Digraph, HyperCubeDigraph>();
kpeter@171
    69
//    checkDigraphIterators<HyperCubeDigraph>();
kpeter@171
    70
//  }
kpeter@171
    71
}
deba@57
    72
kpeter@171
    73
template <typename Digraph>
kpeter@171
    74
void check_graph_validity() {
kpeter@171
    75
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@171
    76
  Digraph g;
kpeter@171
    77
kpeter@171
    78
  Node
kpeter@171
    79
    n1 = g.addNode(),
kpeter@171
    80
    n2 = g.addNode(),
kpeter@171
    81
    n3 = g.addNode();
kpeter@171
    82
kpeter@171
    83
  Arc
kpeter@171
    84
    e1 = g.addArc(n1, n2),
kpeter@171
    85
    e2 = g.addArc(n2, n3);
kpeter@171
    86
kpeter@171
    87
  check(g.valid(n1), "Wrong validity check");
kpeter@171
    88
  check(g.valid(e1), "Wrong validity check");
kpeter@171
    89
kpeter@171
    90
  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
kpeter@171
    91
  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
kpeter@171
    92
}
kpeter@171
    93
kpeter@171
    94
template <typename Digraph>
kpeter@171
    95
void check_graph_validity_erase() {
kpeter@171
    96
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@171
    97
  Digraph g;
kpeter@171
    98
kpeter@171
    99
  Node
kpeter@171
   100
    n1 = g.addNode(),
kpeter@171
   101
    n2 = g.addNode(),
kpeter@171
   102
    n3 = g.addNode();
kpeter@171
   103
kpeter@171
   104
  Arc
kpeter@171
   105
    e1 = g.addArc(n1, n2),
kpeter@171
   106
    e2 = g.addArc(n2, n3);
kpeter@171
   107
kpeter@171
   108
  check(g.valid(n1), "Wrong validity check");
kpeter@171
   109
  check(g.valid(e1), "Wrong validity check");
kpeter@171
   110
kpeter@171
   111
  g.erase(n1);
kpeter@171
   112
kpeter@171
   113
  check(!g.valid(n1), "Wrong validity check");
kpeter@171
   114
  check(g.valid(n2), "Wrong validity check");
kpeter@171
   115
  check(g.valid(n3), "Wrong validity check");
kpeter@171
   116
  check(!g.valid(e1), "Wrong validity check");
kpeter@171
   117
  check(g.valid(e2), "Wrong validity check");
kpeter@171
   118
kpeter@171
   119
  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
kpeter@171
   120
  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
kpeter@171
   121
}
kpeter@171
   122
kpeter@171
   123
void check_digraphs() {
kpeter@171
   124
  { // Checking ListDigraph
deba@57
   125
    checkDigraph<ListDigraph>();
deba@57
   126
    checkGraphNodeMap<ListDigraph>();
deba@57
   127
    checkGraphArcMap<ListDigraph>();
kpeter@171
   128
kpeter@171
   129
    check_graph_validity_erase<ListDigraph>();
deba@57
   130
  }
kpeter@171
   131
  { // Checking SmartDigraph
kpeter@171
   132
    checkDigraph<SmartDigraph>();
kpeter@171
   133
    checkGraphNodeMap<SmartDigraph>();
kpeter@171
   134
    checkGraphArcMap<SmartDigraph>();
deba@57
   135
kpeter@171
   136
    check_graph_validity<SmartDigraph>();
kpeter@171
   137
  }
kpeter@171
   138
}
deba@57
   139
kpeter@171
   140
int main() {
kpeter@171
   141
  check_concepts();
kpeter@171
   142
  check_digraphs();
deba@57
   143
  return 0;
deba@57
   144
}