test/bpugraph_test.cc
author deba
Tue, 31 Oct 2006 14:27:58 +0000
changeset 2282 9d7b12f83daa
parent 2231 06faf3f06d67
child 2391 14a343be7a5a
permissions -rw-r--r--
Bug fixes
deba@2231
     1
/* -*- C++ -*-
deba@2231
     2
 *
deba@2231
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@2231
     4
 *
deba@2231
     5
 * Copyright (C) 2003-2006
deba@2231
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@2231
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@2231
     8
 *
deba@2231
     9
 * Permission to use, modify and distribute this software is granted
deba@2231
    10
 * provided that this copyright notice appears in all copies. For
deba@2231
    11
 * precise terms see the accompanying LICENSE file.
deba@2231
    12
 *
deba@2231
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@2231
    14
 * express or implied, and with no claim as to its suitability for any
deba@2231
    15
 * purpose.
deba@2231
    16
 *
deba@2231
    17
 */
deba@2231
    18
alpar@2260
    19
#include <lemon/concepts/bpugraph.h>
deba@2231
    20
#include <lemon/list_graph.h>
deba@2231
    21
#include <lemon/smart_graph.h>
deba@2231
    22
#include <lemon/full_graph.h>
deba@2231
    23
#include <lemon/grid_ugraph.h>
deba@2231
    24
deba@2231
    25
#include <lemon/graph_utils.h>
deba@2231
    26
deba@2231
    27
#include "test_tools.h"
deba@2231
    28
deba@2231
    29
deba@2231
    30
using namespace lemon;
alpar@2260
    31
using namespace lemon::concepts;
deba@2231
    32
deba@2231
    33
void check_concepts() {
deba@2231
    34
deba@2231
    35
  { // checking graph components
deba@2231
    36
    checkConcept<BaseBpUGraphComponent, BaseBpUGraphComponent >();
deba@2231
    37
deba@2231
    38
    checkConcept<IDableBpUGraphComponent<>, 
deba@2231
    39
      IDableBpUGraphComponent<> >();
deba@2231
    40
deba@2231
    41
    checkConcept<IterableBpUGraphComponent<>, 
deba@2231
    42
      IterableBpUGraphComponent<> >();
deba@2231
    43
deba@2231
    44
    checkConcept<MappableBpUGraphComponent<>, 
deba@2231
    45
      MappableBpUGraphComponent<> >();
deba@2231
    46
deba@2231
    47
  }
deba@2231
    48
  {
deba@2231
    49
    checkConcept<BpUGraph, ListBpUGraph>();
deba@2231
    50
    
deba@2231
    51
    checkConcept<BpUGraph, SmartBpUGraph>();
deba@2231
    52
    
deba@2231
    53
    checkConcept<BpUGraph, FullBpUGraph>();
deba@2231
    54
    
deba@2231
    55
    checkConcept<BpUGraph, BpUGraph>();
deba@2231
    56
    
deba@2231
    57
  }
deba@2231
    58
}
deba@2231
    59
deba@2231
    60
template <typename Graph>
deba@2231
    61
void check_item_counts(Graph &g, int an, int bn, int e) {
deba@2231
    62
  int nn = 0;
deba@2231
    63
  for (typename Graph::NodeIt it(g); it != INVALID; ++it) {
deba@2231
    64
    ++nn;
deba@2231
    65
  }
deba@2231
    66
deba@2231
    67
  check(nn == an + bn, "Wrong node number.");
deba@2231
    68
  check(countNodes(g) == an + bn, "Wrong node number.");
deba@2231
    69
deba@2231
    70
  int ann = 0;
deba@2231
    71
  for (typename Graph::ANodeIt it(g); it != INVALID; ++it) {
deba@2231
    72
    ++ann;
deba@2231
    73
  }
deba@2231
    74
deba@2231
    75
  check(ann == an, "Wrong node number.");
deba@2231
    76
  check(countANodes(g) == an, "Wrong node number.");
deba@2231
    77
deba@2231
    78
  int bnn = 0;
deba@2231
    79
  for (typename Graph::BNodeIt it(g); it != INVALID; ++it) {
deba@2231
    80
    ++bnn;
deba@2231
    81
  }
deba@2231
    82
deba@2231
    83
  check(bnn == bn, "Wrong node number.");
deba@2231
    84
  check(countBNodes(g) == bn, "Wrong node number.");
deba@2231
    85
deba@2231
    86
  int ee = 0;
deba@2231
    87
  for (typename Graph::EdgeIt it(g); it != INVALID; ++it) {
deba@2231
    88
    ++ee;
deba@2231
    89
  }
deba@2231
    90
deba@2231
    91
  check(ee == 2*e, "Wrong edge number.");
deba@2231
    92
  check(countEdges(g) == 2*e, "Wrong edge number.");
deba@2231
    93
deba@2231
    94
  int uee = 0;
deba@2231
    95
  for (typename Graph::UEdgeIt it(g); it != INVALID; ++it) {
deba@2231
    96
    ++uee;
deba@2231
    97
  }
deba@2231
    98
deba@2231
    99
  check(uee == e, "Wrong uedge number.");
deba@2231
   100
  check(countUEdges(g) == e, "Wrong uedge number.");
deba@2231
   101
}
deba@2231
   102
deba@2231
   103
template <typename Graph>
deba@2231
   104
void check_graph() {
deba@2231
   105
deba@2231
   106
  typedef typename Graph::Node Node;
deba@2231
   107
  typedef typename Graph::UEdge UEdge;
deba@2231
   108
  typedef typename Graph::Edge Edge;
deba@2231
   109
  typedef typename Graph::NodeIt NodeIt;
deba@2231
   110
  typedef typename Graph::UEdgeIt UEdgeIt;
deba@2231
   111
  typedef typename Graph::EdgeIt EdgeIt;
deba@2231
   112
deba@2231
   113
  Graph g;
deba@2231
   114
deba@2231
   115
  check_item_counts(g, 0, 0, 0);
deba@2231
   116
deba@2231
   117
  Node
deba@2231
   118
    an1 = g.addANode(),
deba@2231
   119
    an2 = g.addANode(),
deba@2231
   120
    an3 = g.addANode(),
deba@2231
   121
    bn1 = g.addBNode(),
deba@2231
   122
    bn2 = g.addBNode();
deba@2231
   123
deba@2231
   124
  UEdge
deba@2231
   125
    e1 = g.addEdge(an1, bn1),
deba@2231
   126
    e2 = g.addEdge(an2, bn1),
deba@2231
   127
    e3 = g.addEdge(an3, bn2);
deba@2231
   128
deba@2231
   129
  check_item_counts(g, 3, 2, 3);
deba@2231
   130
}
deba@2231
   131
deba@2231
   132
int main() {
deba@2231
   133
  check_concepts();
deba@2231
   134
deba@2231
   135
  check_graph<ListBpUGraph>();
deba@2231
   136
  check_graph<SmartBpUGraph>();
deba@2231
   137
deba@2231
   138
  {
deba@2231
   139
    FullBpUGraph g(5, 10);
deba@2231
   140
    check_item_counts(g, 5, 10, 50);
deba@2231
   141
  }
deba@2231
   142
deba@2231
   143
  std::cout << __FILE__ ": All tests passed.\n";
deba@2231
   144
deba@2231
   145
  return 0;
deba@2231
   146
}