COIN-OR::LEMON - Graph Library

Changeset 171:02f4d5d9bfd7 in lemon for test/digraph_test.cc


Ignore:
Timestamp:
06/15/08 22:05:23 (16 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/digraph_test.cc

    r107 r171  
    1717 */
    1818
    19 #include <iostream>
    20 #include <vector>
    21 
    2219#include <lemon/concepts/digraph.h>
    2320#include <lemon/list_graph.h>
    24 //#include <lemon/smart_graph.h>
     21#include <lemon/smart_graph.h>
    2522//#include <lemon/full_graph.h>
    2623//#include <lemon/hypercube_graph.h>
    2724
    2825#include "test_tools.h"
    29 #include "digraph_test.h"
    30 #include "map_test.h"
    31 
     26#include "graph_test.h"
     27#include "graph_maps_test.h"
    3228
    3329using namespace lemon;
    3430using namespace lemon::concepts;
    3531
    36 
    37 int main() {
    38   { // checking digraph components
     32void check_concepts() {
     33  { // Checking digraph components
    3934    checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
    4035
     
    4742    checkConcept<MappableDigraphComponent<>,
    4843      MappableDigraphComponent<> >();
    49 
    5044  }
    51   { // checking skeleton digraphs
     45  { // Checking skeleton digraph
    5246    checkConcept<Digraph, Digraph>();
    5347  }
    54   { // checking list digraph
    55     checkConcept<Digraph, ListDigraph >();
     48  { // Checking ListDigraph
     49    checkConcept<Digraph, ListDigraph>();
    5650    checkConcept<AlterableDigraphComponent<>, ListDigraph>();
    5751    checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
    5852    checkConcept<ClearableDigraphComponent<>, ListDigraph>();
    5953    checkConcept<ErasableDigraphComponent<>, ListDigraph>();
     54    checkDigraphIterators<ListDigraph>();
     55  }
     56  { // Checking SmartDigraph
     57    checkConcept<Digraph, SmartDigraph>();
     58    checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
     59    checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
     60    checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
     61    checkDigraphIterators<SmartDigraph>();
     62  }
     63//  { // Checking FullDigraph
     64//    checkConcept<Digraph, FullDigraph>();
     65//    checkDigraphIterators<FullDigraph>();
     66//  }
     67//  { // Checking HyperCubeDigraph
     68//    checkConcept<Digraph, HyperCubeDigraph>();
     69//    checkDigraphIterators<HyperCubeDigraph>();
     70//  }
     71}
    6072
     73template <typename Digraph>
     74void check_graph_validity() {
     75  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
     76  Digraph g;
     77
     78  Node
     79    n1 = g.addNode(),
     80    n2 = g.addNode(),
     81    n3 = g.addNode();
     82
     83  Arc
     84    e1 = g.addArc(n1, n2),
     85    e2 = g.addArc(n2, n3);
     86
     87  check(g.valid(n1), "Wrong validity check");
     88  check(g.valid(e1), "Wrong validity check");
     89
     90  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
     91  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
     92}
     93
     94template <typename Digraph>
     95void check_graph_validity_erase() {
     96  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
     97  Digraph g;
     98
     99  Node
     100    n1 = g.addNode(),
     101    n2 = g.addNode(),
     102    n3 = g.addNode();
     103
     104  Arc
     105    e1 = g.addArc(n1, n2),
     106    e2 = g.addArc(n2, n3);
     107
     108  check(g.valid(n1), "Wrong validity check");
     109  check(g.valid(e1), "Wrong validity check");
     110
     111  g.erase(n1);
     112
     113  check(!g.valid(n1), "Wrong validity check");
     114  check(g.valid(n2), "Wrong validity check");
     115  check(g.valid(n3), "Wrong validity check");
     116  check(!g.valid(e1), "Wrong validity check");
     117  check(g.valid(e2), "Wrong validity check");
     118
     119  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
     120  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
     121}
     122
     123void check_digraphs() {
     124  { // Checking ListDigraph
    61125    checkDigraph<ListDigraph>();
    62126    checkGraphNodeMap<ListDigraph>();
    63127    checkGraphArcMap<ListDigraph>();
     128
     129    check_graph_validity_erase<ListDigraph>();
    64130  }
    65 //   { // checking smart digraph
    66 //     checkConcept<Digraph, SmartDigraph >();
     131  { // Checking SmartDigraph
     132    checkDigraph<SmartDigraph>();
     133    checkGraphNodeMap<SmartDigraph>();
     134    checkGraphArcMap<SmartDigraph>();
    67135
    68 //     checkDigraph<SmartDigraph>();
    69 //     checkDigraphNodeMap<SmartDigraph>();
    70 //     checkDigraphArcMap<SmartDigraph>();
    71 //   }
    72 //   { // checking full digraph
    73 //     checkConcept<Digraph, FullDigraph >();
    74 //   }
    75 //   { // checking full digraph
    76 //     checkConcept<Digraph, HyperCubeDigraph >();
    77 //   }
     136    check_graph_validity<SmartDigraph>();
     137  }
     138}
    78139
    79   std::cout << __FILE__ ": All tests passed.\n";
    80 
     140int main() {
     141  check_concepts();
     142  check_digraphs();
    81143  return 0;
    82144}
Note: See TracChangeset for help on using the changeset viewer.