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