test/graph_utils_test.cc
author hegyi
Mon, 13 Jun 2005 10:30:08 +0000
changeset 1474 75c6d2eb187a
parent 1435 8e85e6bbefdf
child 1568 f694f75de683
permissions -rw-r--r--
Edge creation is available.
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>();
klao@946
    53
  }
klao@946
    54
  { // checking smart graph
klao@946
    55
    checkGraphCounters<SmartGraph>();
klao@946
    56
  }
klao@977
    57
  {
klao@977
    58
    int num = 5;
klao@977
    59
    FullGraph fg(num);
klao@977
    60
    check(countNodes(fg) == num, "FullGraph: wrong node number.");
klao@977
    61
    check(countEdges(fg) == num*num, "FullGraph: wrong edge number.");    
klao@977
    62
  }
klao@946
    63
alpar@1459
    64
  //check In/OutDegMap (and SnapShot feature)
alpar@1459
    65
alpar@1459
    66
  checkSnapDeg<ListGraph>();
alpar@1459
    67
  checkSnapDeg<SmartGraph>();
alpar@1459
    68
  
alpar@1459
    69
alpar@1459
    70
  ///Everything is OK
klao@946
    71
  std::cout << __FILE__ ": All tests passed.\n";
klao@946
    72
klao@946
    73
  return 0;
klao@946
    74
}