src/test/graph_test.h
author alpar
Sun, 19 Sep 2004 12:26:42 +0000
changeset 882 46974f296c4a
parent 800 b70a494b4912
child 891 74589d20dbc3
permissions -rw-r--r--
This was forgotten to add from the previous commit.
alpar@800
     1
#ifndef HUGO_TEST_GRAPH_TEST_H
alpar@800
     2
#define HUGO_TEST_GRAPH_TEST_H
alpar@800
     3
alpar@800
     4
alpar@800
     5
#include "test_tools.h"
alpar@800
     6
alpar@800
     7
//! \ingroup misc
alpar@800
     8
//! \file
alpar@800
     9
//! \brief Some utility to  test graph classes.
alpar@800
    10
namespace hugo {
alpar@800
    11
alpar@800
    12
alpar@800
    13
template<class Graph> void checkCompileStaticGraph(Graph &G) 
alpar@800
    14
{
alpar@800
    15
  typedef typename Graph::Node Node;
alpar@800
    16
  typedef typename Graph::NodeIt NodeIt;
alpar@800
    17
  typedef typename Graph::Edge Edge;
alpar@800
    18
  typedef typename Graph::EdgeIt EdgeIt;
alpar@800
    19
  typedef typename Graph::InEdgeIt InEdgeIt;
alpar@800
    20
  typedef typename Graph::OutEdgeIt OutEdgeIt;
alpar@800
    21
  
alpar@800
    22
  {
alpar@800
    23
    Node i; Node j(i); Node k(INVALID);
alpar@800
    24
    i=j;
alpar@856
    25
    bool b; b=true;
alpar@800
    26
    b=(i==INVALID); b=(i!=INVALID);
alpar@800
    27
    b=(i==j); b=(i!=j); b=(i<j);
alpar@800
    28
  }
alpar@800
    29
  {
alpar@800
    30
    NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
alpar@800
    31
    i=j;
alpar@800
    32
    j=G.first(i);
alpar@800
    33
    j=++i;
alpar@856
    34
    bool b; b=true;
alpar@800
    35
    b=(i==INVALID); b=(i!=INVALID);
alpar@800
    36
    Node n(i);
alpar@800
    37
    n=i;
alpar@800
    38
    b=(i==j); b=(i!=j); b=(i<j);
alpar@800
    39
    //Node ->NodeIt conversion
alpar@800
    40
    NodeIt ni(G,n);
alpar@800
    41
  }
alpar@800
    42
  {
alpar@800
    43
    Edge i; Edge j(i); Edge k(INVALID);
alpar@800
    44
    i=j;
alpar@856
    45
    bool b; b=true;
alpar@800
    46
    b=(i==INVALID); b=(i!=INVALID);
alpar@800
    47
    b=(i==j); b=(i!=j); b=(i<j);
alpar@800
    48
  }
alpar@800
    49
  {
alpar@800
    50
    EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
alpar@800
    51
    i=j;
alpar@800
    52
    j=G.first(i);
alpar@800
    53
    j=++i;
alpar@856
    54
    bool b; b=true;
alpar@800
    55
    b=(i==INVALID); b=(i!=INVALID);
alpar@800
    56
    Edge e(i);
alpar@800
    57
    e=i;
alpar@800
    58
    b=(i==j); b=(i!=j); b=(i<j);
alpar@800
    59
    //Edge ->EdgeIt conversion
alpar@800
    60
    EdgeIt ei(G,e);
alpar@800
    61
  }
alpar@800
    62
  {
alpar@800
    63
    Node n;
alpar@800
    64
    InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
alpar@800
    65
    i=j;
alpar@800
    66
    j=G.first(i,n);
alpar@800
    67
    j=++i;
alpar@856
    68
    bool b; b=true;
alpar@800
    69
    b=(i==INVALID); b=(i!=INVALID);
alpar@800
    70
    Edge e(i);
alpar@800
    71
    e=i;
alpar@800
    72
    b=(i==j); b=(i!=j); b=(i<j);
alpar@800
    73
    //Edge ->InEdgeIt conversion
alpar@800
    74
    InEdgeIt ei(G,e);
alpar@800
    75
  }
alpar@800
    76
  {
alpar@800
    77
    Node n;
alpar@800
    78
    OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
alpar@800
    79
    i=j;
alpar@800
    80
    j=G.first(i,n);
alpar@800
    81
    j=++i;
alpar@856
    82
    bool b; b=true;
alpar@800
    83
    b=(i==INVALID); b=(i!=INVALID);
alpar@800
    84
    Edge e(i);
alpar@800
    85
    e=i;
alpar@800
    86
    b=(i==j); b=(i!=j); b=(i<j);
alpar@800
    87
    //Edge ->OutEdgeIt conversion
alpar@800
    88
    OutEdgeIt ei(G,e);
alpar@800
    89
  }
alpar@800
    90
  {
alpar@800
    91
    Node n,m;
alpar@800
    92
    n=m=INVALID;
alpar@800
    93
    Edge e;
alpar@800
    94
    e=INVALID;
alpar@800
    95
    n=G.tail(e);
alpar@800
    96
    n=G.head(e);
alpar@800
    97
  }
alpar@800
    98
  // id tests
alpar@800
    99
  { Node n; int i=G.id(n); i=i; }
alpar@800
   100
  { Edge e; int i=G.id(e); i=i; }
alpar@800
   101
  //NodeMap tests
alpar@800
   102
  {
alpar@800
   103
    Node k;
alpar@800
   104
    typename Graph::template NodeMap<int> m(G);
alpar@800
   105
    //Const map
alpar@800
   106
    typename Graph::template NodeMap<int> const &cm = m;
alpar@800
   107
    //Inicialize with default value
alpar@800
   108
    typename Graph::template NodeMap<int> mdef(G,12);
alpar@800
   109
    //Copy
alpar@800
   110
    typename Graph::template NodeMap<int> mm(cm);
alpar@800
   111
    //Copy from another type
alpar@800
   112
    typename Graph::template NodeMap<double> dm(cm);
alpar@800
   113
    int v;
alpar@800
   114
    v=m[k]; m[k]=v; m.set(k,v);
alpar@800
   115
    v=cm[k];
alpar@800
   116
    
alpar@800
   117
    m=cm;  
alpar@800
   118
    dm=cm; //Copy from another type
alpar@800
   119
    {
alpar@800
   120
      //Check the typedef's
alpar@800
   121
      typename Graph::template NodeMap<int>::ValueType val;
alpar@800
   122
      val=1;
alpar@800
   123
      typename Graph::template NodeMap<int>::KeyType key;
alpar@800
   124
      key = typename Graph::NodeIt(G);
alpar@800
   125
    }
alpar@800
   126
  }  
alpar@800
   127
  { //bool NodeMap
alpar@800
   128
    Node k;
alpar@800
   129
    typename Graph::template NodeMap<bool> m(G);
alpar@800
   130
    typename Graph::template NodeMap<bool> const &cm = m;  //Const map
alpar@800
   131
    //Inicialize with default value
alpar@800
   132
    typename Graph::template NodeMap<bool> mdef(G,12);
alpar@800
   133
    typename Graph::template NodeMap<bool> mm(cm);   //Copy
alpar@800
   134
    typename Graph::template NodeMap<int> dm(cm); //Copy from another type
alpar@800
   135
    bool v;
alpar@800
   136
    v=m[k]; m[k]=v; m.set(k,v);
alpar@800
   137
    v=cm[k];
alpar@800
   138
    
alpar@800
   139
    m=cm;  
alpar@800
   140
    dm=cm; //Copy from another type
alpar@800
   141
    m=dm; //Copy to another type
alpar@800
   142
alpar@800
   143
    {
alpar@800
   144
      //Check the typedef's
alpar@800
   145
      typename Graph::template NodeMap<bool>::ValueType val;
alpar@800
   146
      val=true;
alpar@800
   147
      typename Graph::template NodeMap<bool>::KeyType key;
alpar@800
   148
      key= typename Graph::NodeIt(G);
alpar@800
   149
    }
alpar@800
   150
  }
alpar@800
   151
  //EdgeMap tests
alpar@800
   152
  {
alpar@800
   153
    Edge k;
alpar@800
   154
    typename Graph::template EdgeMap<int> m(G);
alpar@800
   155
    typename Graph::template EdgeMap<int> const &cm = m;  //Const map
alpar@800
   156
    //Inicialize with default value
alpar@800
   157
    typename Graph::template EdgeMap<int> mdef(G,12);
alpar@800
   158
    typename Graph::template EdgeMap<int> mm(cm);   //Copy
alpar@800
   159
    typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
alpar@800
   160
    int v;
alpar@800
   161
    v=m[k]; m[k]=v; m.set(k,v);
alpar@800
   162
    v=cm[k];
alpar@800
   163
    
alpar@800
   164
    m=cm;  
alpar@800
   165
    dm=cm; //Copy from another type
alpar@800
   166
    {
alpar@800
   167
      //Check the typedef's
alpar@800
   168
      typename Graph::template EdgeMap<int>::ValueType val;
alpar@800
   169
      val=1;
alpar@800
   170
      typename Graph::template EdgeMap<int>::KeyType key;
alpar@800
   171
      key= typename Graph::EdgeIt(G);
alpar@800
   172
    }
alpar@800
   173
  }  
alpar@800
   174
  { //bool EdgeMap
alpar@800
   175
    Edge k;
alpar@800
   176
    typename Graph::template EdgeMap<bool> m(G);
alpar@800
   177
    typename Graph::template EdgeMap<bool> const &cm = m;  //Const map
alpar@800
   178
    //Inicialize with default value
alpar@800
   179
    typename Graph::template EdgeMap<bool> mdef(G,12);
alpar@800
   180
    typename Graph::template EdgeMap<bool> mm(cm);   //Copy
alpar@800
   181
    typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
alpar@800
   182
    bool v;
alpar@800
   183
    v=m[k]; m[k]=v; m.set(k,v);
alpar@800
   184
    v=cm[k];
alpar@800
   185
    
alpar@800
   186
    m=cm;  
alpar@800
   187
    dm=cm; //Copy from another type
alpar@800
   188
    m=dm; //Copy to another type
alpar@800
   189
    {
alpar@800
   190
      //Check the typedef's
alpar@800
   191
      typename Graph::template EdgeMap<bool>::ValueType val;
alpar@800
   192
      val=true;
alpar@800
   193
      typename Graph::template EdgeMap<bool>::KeyType key;
alpar@800
   194
      key= typename Graph::EdgeIt(G);
alpar@800
   195
    }
alpar@800
   196
  }
alpar@800
   197
}
alpar@800
   198
alpar@800
   199
template<class Graph> void checkCompileGraph(Graph &G) 
alpar@800
   200
{
alpar@800
   201
  checkCompileStaticGraph(G);
alpar@800
   202
alpar@800
   203
  typedef typename Graph::Node Node;
alpar@800
   204
  typedef typename Graph::NodeIt NodeIt;
alpar@800
   205
  typedef typename Graph::Edge Edge;
alpar@800
   206
  typedef typename Graph::EdgeIt EdgeIt;
alpar@800
   207
  typedef typename Graph::InEdgeIt InEdgeIt;
alpar@800
   208
  typedef typename Graph::OutEdgeIt OutEdgeIt;
alpar@800
   209
  
alpar@800
   210
  Node n,m;
alpar@800
   211
  n=G.addNode();
alpar@800
   212
  m=G.addNode();
alpar@800
   213
  Edge e;
alpar@800
   214
  e=G.addEdge(n,m); 
alpar@800
   215
  
alpar@800
   216
  //  G.clear();
alpar@800
   217
}
alpar@800
   218
alpar@800
   219
template<class Graph> void checkCompileGraphEraseEdge(Graph &G) 
alpar@800
   220
{
alpar@800
   221
  typename Graph::Edge e;
alpar@800
   222
  G.erase(e);
alpar@800
   223
}
alpar@800
   224
alpar@800
   225
template<class Graph> void checkCompileGraphEraseNode(Graph &G) 
alpar@800
   226
{
alpar@800
   227
  typename Graph::Node n;
alpar@800
   228
  G.erase(n);
alpar@800
   229
}
alpar@800
   230
alpar@800
   231
template<class Graph> void checkCompileErasableGraph(Graph &G) 
alpar@800
   232
{
alpar@800
   233
  checkCompileGraph(G);
alpar@800
   234
  checkCompileGraphEraseNode(G);
alpar@800
   235
  checkCompileGraphEraseEdge(G);
alpar@800
   236
}
alpar@800
   237
alpar@800
   238
template<class Graph> void checkCompileGraphFindEdge(Graph &G) 
alpar@800
   239
{
alpar@800
   240
  typedef typename Graph::NodeIt Node;
alpar@800
   241
  typedef typename Graph::NodeIt NodeIt;
alpar@800
   242
alpar@800
   243
  G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
alpar@800
   244
  G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));  
alpar@800
   245
}
alpar@800
   246
alpar@800
   247
template<class Graph> void checkGraphNodeList(Graph &G, int nn)
alpar@800
   248
{
alpar@800
   249
  typename Graph::NodeIt n(G);
alpar@800
   250
  for(int i=0;i<nn;i++) {
alpar@800
   251
    check(n!=INVALID,"Wrong Node list linking.");
alpar@800
   252
    ++n;
alpar@800
   253
  }
alpar@800
   254
  check(n==INVALID,"Wrong Node list linking.");
alpar@800
   255
}
alpar@800
   256
alpar@800
   257
template<class Graph> void checkGraphEdgeList(Graph &G, int nn)
alpar@800
   258
{
alpar@800
   259
  typedef typename Graph::EdgeIt EdgeIt;
alpar@800
   260
alpar@800
   261
  EdgeIt e(G);
alpar@800
   262
  for(int i=0;i<nn;i++) {
alpar@800
   263
    check(e!=INVALID,"Wrong Edge list linking.");
alpar@800
   264
    ++e;
alpar@800
   265
  }
alpar@800
   266
  check(e==INVALID,"Wrong Edge list linking.");
alpar@800
   267
}
alpar@800
   268
alpar@800
   269
template<class Graph> void checkGraphOutEdgeList(Graph &G,
alpar@800
   270
						 typename Graph::Node n,
alpar@800
   271
						 int nn)
alpar@800
   272
{
alpar@800
   273
  typename Graph::OutEdgeIt e(G,n);
alpar@800
   274
  for(int i=0;i<nn;i++) {
alpar@800
   275
    check(e!=INVALID,"Wrong OutEdge list linking.");
alpar@800
   276
    ++e;
alpar@800
   277
  }
alpar@800
   278
  check(e==INVALID,"Wrong OutEdge list linking.");
alpar@800
   279
}
alpar@800
   280
alpar@800
   281
template<class Graph> void checkGraphInEdgeList(Graph &G,
alpar@800
   282
						typename Graph::Node n,
alpar@800
   283
						int nn)
alpar@800
   284
{
alpar@800
   285
  typename Graph::InEdgeIt e(G,n);
alpar@800
   286
  for(int i=0;i<nn;i++) {
alpar@800
   287
    check(e!=INVALID,"Wrong InEdge list linking.");
alpar@800
   288
    ++e;
alpar@800
   289
  }
alpar@800
   290
  check(e==INVALID,"Wrong InEdge list linking.");
alpar@800
   291
}
alpar@800
   292
alpar@800
   293
///\file
alpar@800
   294
///\todo Check head(), tail() as well;
alpar@800
   295
alpar@800
   296
  
alpar@800
   297
} //namespace hugo
alpar@800
   298
alpar@800
   299
alpar@800
   300
#endif