COIN-OR::LEMON - Graph Library

Changeset 171:02f4d5d9bfd7 in lemon-1.0 for test/graph_test.cc


Ignore:
Timestamp:
06/15/08 22:05:23 (11 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Children:
172:c94a80f38d7f, 173:b026e9779b28, 175:4eb8900a865c
Phase:
public
Message:

Improve and redesign test programs + unify their output (ticket #25)

  • Move graph related utilities form test_tools.h to graph_test.h.
  • Move the contents of graph_utils_test.h to graph_utils_test.cc.
  • Rename map_test.h -> graph_maps_test.h.
  • Rename digraph_test.h -> graph_test.h.
  • Many improvements in the following files:
    • digraph_test.cc
    • graph_test.cc
    • graph_test.h
    • graph_maps_test.h
    • graph_utils_test.cc
    • bfs_test.cc
    • dfs_test.cc
    • counter_test.cc
  • Test programs print messages only if it really seems necessary.
  • Remove \file commands form .cc test files.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/graph_test.cc

    r149 r171  
    2323// #include <lemon/grid_graph.h>
    2424
    25 #include <lemon/graph_utils.h>
    26 
    2725#include "test_tools.h"
    28 
     26#include "graph_test.h"
     27#include "graph_maps_test.h"
    2928
    3029using namespace lemon;
     
    3231
    3332void check_concepts() {
    34 
    35   { // checking digraph components
     33  { // Checking graph components
    3634    checkConcept<BaseGraphComponent, BaseGraphComponent >();
    3735
     
    4442    checkConcept<MappableGraphComponent<>,
    4543      MappableGraphComponent<> >();
    46 
    47   }
    48   {
    49     checkConcept<Graph, ListGraph>();   
    50     checkConcept<Graph, SmartGraph>();   
    51 //     checkConcept<Graph, FullGraph>();   
    52 //     checkConcept<Graph, Graph>();   
    53 //     checkConcept<Graph, GridGraph>();
    54   }
     44  }
     45  { // Checking skeleton graph
     46    checkConcept<Graph, Graph>();
     47  }
     48  { // Checking ListGraph
     49    checkConcept<Graph, ListGraph>();
     50    checkConcept<AlterableGraphComponent<>, ListGraph>();
     51    checkConcept<ExtendableGraphComponent<>, ListGraph>();
     52    checkConcept<ClearableGraphComponent<>, ListGraph>();
     53    checkConcept<ErasableGraphComponent<>, ListGraph>();
     54    checkGraphIterators<ListGraph>();
     55  }
     56  { // Checking SmartGraph
     57    checkConcept<Graph, SmartGraph>();
     58    checkConcept<AlterableGraphComponent<>, SmartGraph>();
     59    checkConcept<ExtendableGraphComponent<>, SmartGraph>();
     60    checkConcept<ClearableGraphComponent<>, SmartGraph>();
     61    checkGraphIterators<SmartGraph>();
     62  }
     63//  { // Checking FullGraph
     64//    checkConcept<Graph, FullGraph>();
     65//    checkGraphIterators<FullGraph>();
     66//  }
     67//  { // Checking GridGraph
     68//    checkConcept<Graph, GridGraph>();
     69//    checkGraphIterators<GridGraph>();
     70//  }
    5571}
    5672
    5773template <typename Graph>
    58 void check_item_counts(Graph &g, int n, int e) {
    59   int nn = 0;
    60   for (typename Graph::NodeIt it(g); it != INVALID; ++it) {
    61     ++nn;
    62   }
    63 
    64   check(nn == n, "Wrong node number.");
    65   //  check(countNodes(g) == n, "Wrong node number.");
    66 
    67   int ee = 0;
    68   for (typename Graph::ArcIt it(g); it != INVALID; ++it) {
    69     ++ee;
    70   }
    71 
    72   check(ee == 2*e, "Wrong arc number.");
    73   //  check(countArcs(g) == 2*e, "Wrong arc number.");
    74 
    75   int uee = 0;
    76   for (typename Graph::EdgeIt it(g); it != INVALID; ++it) {
    77     ++uee;
    78   }
    79 
    80   check(uee == e, "Wrong edge number.");
    81   //  check(countEdges(g) == e, "Wrong edge number.");
    82 }
    83 
    84 template <typename Graph>
    85 void check_graph_counts() {
    86 
     74void check_graph_validity() {
    8775  TEMPLATE_GRAPH_TYPEDEFS(Graph);
    8876  Graph g;
    89 
    90   check_item_counts(g,0,0);
    9177
    9278  Node
     
    9985    e2 = g.addEdge(n2, n3);
    10086
    101   check_item_counts(g,3,2);
     87  check(g.valid(n1), "Wrong validity check");
     88  check(g.valid(e1), "Wrong validity check");
     89  check(g.valid(g.direct(e1, true)), "Wrong validity check");
     90
     91  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
     92  check(!g.valid(g.edgeFromId(-1)), "Wrong validity check");
     93  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
    10294}
    10395
    10496template <typename Graph>
    105 void check_graph_validity() {
    106 
     97void check_graph_validity_erase() {
    10798  TEMPLATE_GRAPH_TYPEDEFS(Graph);
    10899  Graph g;
    109 
    110   check_item_counts(g,0,0);
    111100
    112101  Node
     
    119108    e2 = g.addEdge(n2, n3);
    120109
    121   check(g.valid(n1), "Validity check");
    122   check(g.valid(e1), "Validity check");
    123   check(g.valid(g.direct(e1, true)), "Validity check");
    124 
    125   check(!g.valid(g.nodeFromId(-1)), "Validity check");
    126   check(!g.valid(g.edgeFromId(-1)), "Validity check");
    127   check(!g.valid(g.arcFromId(-1)), "Validity check");
    128    
    129 }
    130 
    131 template <typename Graph>
    132 void check_graph_validity_erase() {
    133 
    134   TEMPLATE_GRAPH_TYPEDEFS(Graph);
    135   Graph g;
    136 
    137   check_item_counts(g,0,0);
    138 
    139   Node
    140     n1 = g.addNode(),
    141     n2 = g.addNode(),
    142     n3 = g.addNode();
    143 
    144   Edge
    145     e1 = g.addEdge(n1, n2),
    146     e2 = g.addEdge(n2, n3);
    147 
    148   check(g.valid(n1), "Validity check");
    149   check(g.valid(e1), "Validity check");
    150   check(g.valid(g.direct(e1, true)), "Validity check");
     110  check(g.valid(n1), "Wrong validity check");
     111  check(g.valid(e1), "Wrong validity check");
     112  check(g.valid(g.direct(e1, true)), "Wrong validity check");
    151113
    152114  g.erase(n1);
    153115
    154   check(!g.valid(n1), "Validity check");
    155   check(g.valid(n2), "Validity check");
    156   check(g.valid(n3), "Validity check");
    157   check(!g.valid(e1), "Validity check");
    158   check(g.valid(e2), "Validity check");
    159 
    160   check(!g.valid(g.nodeFromId(-1)), "Validity check");
    161   check(!g.valid(g.edgeFromId(-1)), "Validity check");
    162   check(!g.valid(g.arcFromId(-1)), "Validity check");
    163    
    164 }
    165 
    166 
     116  check(!g.valid(n1), "Wrong validity check");
     117  check(g.valid(n2), "Wrong validity check");
     118  check(g.valid(n3), "Wrong validity check");
     119  check(!g.valid(e1), "Wrong validity check");
     120  check(g.valid(e2), "Wrong validity check");
     121
     122  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
     123  check(!g.valid(g.edgeFromId(-1)), "Wrong validity check");
     124  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
     125}
    167126
    168127// void checkGridGraph(const GridGraph& g, int w, int h) {
     
    210169// }
    211170
     171void check_graphs() {
     172  { // Checking ListGraph
     173    checkGraph<ListGraph>();
     174    checkGraphNodeMap<ListGraph>();
     175    checkGraphEdgeMap<ListGraph>();
     176
     177    check_graph_validity_erase<ListGraph>();
     178  }
     179  { // Checking SmartGraph
     180    checkGraph<SmartGraph>();
     181    checkGraphNodeMap<SmartGraph>();
     182    checkGraphEdgeMap<SmartGraph>();
     183
     184    check_graph_validity<SmartGraph>();
     185  }
     186//   { // Checking FullGraph
     187//     FullGraph g(5);
     188//     checkGraphNodeList(g, 5);
     189//     checkGraphEdgeList(g, 10);
     190//   }
     191//   { // Checking GridGraph
     192//     GridGraph g(5, 6);
     193//     checkGraphNodeList(g, 30);
     194//     checkGraphEdgeList(g, 49);
     195//     checkGridGraph(g, 5, 6);
     196//   }
     197}
     198
    212199int main() {
    213200  check_concepts();
    214 
    215   check_graph_counts<ListGraph>();
    216   check_graph_counts<SmartGraph>();
    217 
    218   check_graph_validity_erase<ListGraph>();
    219   check_graph_validity<SmartGraph>();
    220 
    221 //   {
    222 //     FullGraph g(5);
    223 //     check_item_counts(g, 5, 10);
    224 //   }
    225 
    226 //   {
    227 //     GridGraph g(5, 6);
    228 //     check_item_counts(g, 30, 49);
    229 //     checkGridGraph(g, 5, 6);
    230 //   }
    231 
    232   std::cout << __FILE__ ": All tests passed.\n";
    233 
     201  check_graphs();
    234202  return 0;
    235203}
Note: See TracChangeset for help on using the changeset viewer.