test/graph_utils_test.cc
author deba
Thu, 06 Oct 2005 09:58:21 +0000
changeset 1712 4fb435ad31cf
parent 1459 2ee881cf30a8
child 1728 eb8bb91ba9e2
permissions -rw-r--r--
Little modifications
klao@946
     1
// -*- c++ -*-
klao@946
     2
klao@946
     3
#include <iostream>
klao@946
     4
#include <vector>
klao@946
     5
klao@977
     6
#include <lemon/graph_utils.h>
klao@977
     7
klao@946
     8
#include <lemon/list_graph.h>
klao@946
     9
#include <lemon/smart_graph.h>
klao@946
    10
#include <lemon/full_graph.h>
klao@946
    11
klao@946
    12
#include "test_tools.h"
klao@946
    13
#include "graph_utils_test.h"
klao@946
    14
klao@946
    15
klao@946
    16
using namespace lemon;
klao@946
    17
alpar@1459
    18
template<class Graph>
alpar@1459
    19
void checkSnapDeg() 
alpar@1459
    20
{
alpar@1459
    21
  Graph g;
alpar@1459
    22
  typename Graph::Node n1=g.addNode();
alpar@1459
    23
  typename Graph::Node n2=g.addNode();
alpar@1459
    24
   
alpar@1459
    25
  InDegMap<Graph> ind(g);
alpar@1459
    26
 
alpar@1459
    27
  g.addEdge(n1,n2);
alpar@1459
    28
  
alpar@1459
    29
  typename Graph::SnapShot snap(g);
alpar@1459
    30
  
alpar@1459
    31
  OutDegMap<Graph> outd(g);
alpar@1459
    32
  
alpar@1459
    33
  check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value.");
alpar@1459
    34
  check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value.");
alpar@1459
    35
alpar@1459
    36
  g.addEdge(n1,n2);
alpar@1459
    37
  g.addEdge(n2,n1);
alpar@1459
    38
 
alpar@1459
    39
  check(ind[n1]==1 && ind[n2]==2, "Wrong InDegMap value.");
alpar@1459
    40
  check(outd[n1]==2 && outd[n2]==1, "Wrong OutDegMap value.");
alpar@1459
    41
alpar@1459
    42
  snap.restore();
alpar@1459
    43
alpar@1459
    44
  check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value.");
alpar@1459
    45
  check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value.");
alpar@1459
    46
  
alpar@1459
    47
}
klao@946
    48
klao@946
    49
int main() {
klao@946
    50
  ///\file
klao@946
    51
  { // checking list graph
klao@946
    52
    checkGraphCounters<ListGraph>();
deba@1568
    53
    checkFindEdge<ListGraph>();
klao@946
    54
  }
klao@946
    55
  { // checking smart graph
klao@946
    56
    checkGraphCounters<SmartGraph>();
deba@1568
    57
    checkFindEdge<SmartGraph>();
klao@946
    58
  }
klao@977
    59
  {
klao@977
    60
    int num = 5;
klao@977
    61
    FullGraph fg(num);
klao@977
    62
    check(countNodes(fg) == num, "FullGraph: wrong node number.");
deba@1568
    63
    check(countEdges(fg) == num*num, "FullGraph: wrong edge number.");
deba@1568
    64
    for (FullGraph::NodeIt src(fg); src != INVALID; ++src) {
deba@1568
    65
      for (FullGraph::NodeIt trg(fg); trg != INVALID; ++trg) {
deba@1568
    66
	ConEdgeIt<FullGraph> con(fg, src, trg);
deba@1568
    67
	check(con != INVALID, "There is no connecting edge.");
deba@1568
    68
	check(fg.source(con) == src, "Wrong source.");
deba@1568
    69
	check(fg.target(con) == trg, "Wrong target.");
deba@1568
    70
	check(++con == INVALID, "There is more connecting edge.");
deba@1568
    71
      }
deba@1568
    72
    }
klao@977
    73
  }
klao@946
    74
alpar@1459
    75
  //check In/OutDegMap (and SnapShot feature)
alpar@1459
    76
alpar@1459
    77
  checkSnapDeg<ListGraph>();
alpar@1459
    78
  checkSnapDeg<SmartGraph>();
alpar@1459
    79
  
alpar@1459
    80
alpar@1459
    81
  ///Everything is OK
klao@946
    82
  std::cout << __FILE__ ": All tests passed.\n";
klao@946
    83
klao@946
    84
  return 0;
klao@946
    85
}