test/ugraph_test.cc
changeset 1917 87d3518d73d8
parent 1795 ed3c253b9c29
child 1956 a055123339d5
equal deleted inserted replaced
3:430a366755c2 0:7ab3e06f55ea
     1 // -*- C++ -*-
     1 // -*- C++ -*-
     2 
     2 
     3 #include <lemon/bits/graph_extender.h>
     3 #include <lemon/bits/graph_extender.h>
     4 #include <lemon/concept/undir_graph.h>
     4 #include <lemon/concept/ugraph.h>
     5 #include <lemon/list_graph.h>
     5 #include <lemon/list_graph.h>
     6 #include <lemon/smart_graph.h>
     6 #include <lemon/smart_graph.h>
     7 #include <lemon/full_graph.h>
     7 #include <lemon/full_graph.h>
     8 #include <lemon/grid_graph.h>
     8 #include <lemon/grid_graph.h>
     9 
     9 
    14 
    14 
    15 using namespace lemon;
    15 using namespace lemon;
    16 using namespace lemon::concept;
    16 using namespace lemon::concept;
    17 
    17 
    18 void check_concepts() {
    18 void check_concepts() {
    19   typedef UndirGraphExtender<ListGraphBase> UndirListGraphBase;
    19   typedef UGraphExtender<ListGraphBase> ListUGraphBase;
    20 
    20 
    21   typedef IterableUndirGraphExtender<
    21   typedef IterableUGraphExtender<
    22     AlterableUndirGraphExtender<UndirListGraphBase> > IterableUndirListGraph;
    22     AlterableUGraphExtender<ListUGraphBase> > IterableListUGraph;
    23 
    23 
    24   typedef MappableUndirGraphExtender<IterableUndirListGraph>
    24   typedef MappableUGraphExtender<IterableListUGraph>
    25     MappableUndirListGraph;
    25     MappableListUGraph;
    26 
    26 
    27   typedef ErasableUndirGraphExtender<
    27   typedef ErasableUGraphExtender<
    28     ClearableUndirGraphExtender<
    28     ClearableUGraphExtender<
    29     ExtendableUndirGraphExtender<MappableUndirListGraph> > > Graph;
    29     ExtendableUGraphExtender<MappableListUGraph> > > Graph;
    30 
    30 
    31   checkConcept<BaseIterableUndirGraphConcept, Graph>();
    31   checkConcept<BaseIterableUGraphConcept, Graph>();
    32   checkConcept<IterableUndirGraphConcept, Graph>();
    32   checkConcept<IterableUGraphConcept, Graph>();
    33   checkConcept<MappableUndirGraphConcept, Graph>();
    33   checkConcept<MappableUGraphConcept, Graph>();
    34 
    34 
    35   checkConcept<UndirGraph, Graph>();
    35   checkConcept<UGraph, Graph>();
    36   checkConcept<ErasableUndirGraph, Graph>();
    36   checkConcept<ErasableUGraph, Graph>();
    37 
    37 
    38   checkConcept<UndirGraph, UndirListGraph>();
    38   checkConcept<UGraph, ListUGraph>();
    39   checkConcept<ErasableUndirGraph, UndirListGraph>();
    39   checkConcept<ErasableUGraph, ListUGraph>();
    40 
    40 
    41   checkConcept<UndirGraph, UndirSmartGraph>();
    41   checkConcept<UGraph, SmartUGraph>();
    42   checkConcept<ExtendableUndirGraph, UndirSmartGraph>();
    42   checkConcept<ExtendableUGraph, SmartUGraph>();
    43 
    43 
    44   checkConcept<UndirGraph, UndirFullGraph>();
    44   checkConcept<UGraph, FullUGraph>();
    45 
    45 
    46   checkConcept<UndirGraph, UndirGraph>();
    46   checkConcept<UGraph, UGraph>();
    47 
    47 
    48   checkConcept<UndirGraph, GridGraph>();
    48   checkConcept<UGraph, GridGraph>();
    49 }
    49 }
    50 
    50 
    51 template <typename Graph>
    51 template <typename Graph>
    52 void check_item_counts(Graph &g, int n, int e) {
    52 void check_item_counts(Graph &g, int n, int e) {
    53   int nn = 0;
    53   int nn = 0;
    65 
    65 
    66   check(ee == 2*e, "Wrong edge number.");
    66   check(ee == 2*e, "Wrong edge number.");
    67   check(countEdges(g) == 2*e, "Wrong edge number.");
    67   check(countEdges(g) == 2*e, "Wrong edge number.");
    68 
    68 
    69   int uee = 0;
    69   int uee = 0;
    70   for (typename Graph::UndirEdgeIt it(g); it != INVALID; ++it) {
    70   for (typename Graph::UEdgeIt it(g); it != INVALID; ++it) {
    71     ++uee;
    71     ++uee;
    72   }
    72   }
    73 
    73 
    74   check(uee == e, "Wrong undir edge number.");
    74   check(uee == e, "Wrong uedge number.");
    75   check(countUndirEdges(g) == e, "Wrong undir edge number.");
    75   check(countUEdges(g) == e, "Wrong uedge number.");
    76 }
    76 }
    77 
    77 
    78 template <typename Graph>
    78 template <typename Graph>
    79 void print_items(Graph &g) {
    79 void print_items(Graph &g) {
    80 
    80 
    81   typedef typename Graph::NodeIt NodeIt;
    81   typedef typename Graph::NodeIt NodeIt;
    82   typedef typename Graph::UndirEdgeIt UEdgeIt;
    82   typedef typename Graph::UEdgeIt UEdgeIt;
    83   typedef typename Graph::EdgeIt EdgeIt;
    83   typedef typename Graph::EdgeIt EdgeIt;
    84 
    84 
    85   std::cout << "Nodes" << std::endl;
    85   std::cout << "Nodes" << std::endl;
    86   int i=0;
    86   int i=0;
    87   for(NodeIt it(g); it!=INVALID; ++it, ++i) {
    87   for(NodeIt it(g); it!=INVALID; ++it, ++i) {
    88     std::cout << "  " << i << ": " << g.id(it) << std::endl;
    88     std::cout << "  " << i << ": " << g.id(it) << std::endl;
    89   }
    89   }
    90 
    90 
    91   std::cout << "UndirEdge" << std::endl;
    91   std::cout << "UEdge" << std::endl;
    92   i=0;
    92   i=0;
    93   for(UEdgeIt it(g); it!=INVALID; ++it, ++i) {
    93   for(UEdgeIt it(g); it!=INVALID; ++it, ++i) {
    94     std::cout << "  " << i << ": " << g.id(it) 
    94     std::cout << "  " << i << ": " << g.id(it) 
    95 	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
    95 	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
    96 	 << ")" << std::endl;
    96 	 << ")" << std::endl;
   108 
   108 
   109 template <typename Graph>
   109 template <typename Graph>
   110 void check_graph() {
   110 void check_graph() {
   111 
   111 
   112   typedef typename Graph::Node Node;
   112   typedef typename Graph::Node Node;
   113   typedef typename Graph::UndirEdge UEdge;
   113   typedef typename Graph::UEdge UEdge;
   114   typedef typename Graph::Edge Edge;
   114   typedef typename Graph::Edge Edge;
   115   typedef typename Graph::NodeIt NodeIt;
   115   typedef typename Graph::NodeIt NodeIt;
   116   typedef typename Graph::UndirEdgeIt UEdgeIt;
   116   typedef typename Graph::UEdgeIt UEdgeIt;
   117   typedef typename Graph::EdgeIt EdgeIt;
   117   typedef typename Graph::EdgeIt EdgeIt;
   118 
   118 
   119   Graph g;
   119   Graph g;
   120 
   120 
   121   check_item_counts(g,0,0);
   121   check_item_counts(g,0,0);
   179 }
   179 }
   180 
   180 
   181 int main() {
   181 int main() {
   182   check_concepts();
   182   check_concepts();
   183 
   183 
   184   check_graph<UndirListGraph>();
   184   check_graph<ListUGraph>();
   185   check_graph<UndirSmartGraph>();
   185   check_graph<SmartUGraph>();
   186 
   186 
   187   {
   187   {
   188     UndirFullGraph g(5);
   188     FullUGraph g(5);
   189     check_item_counts(g, 5, 10);
   189     check_item_counts(g, 5, 10);
   190   }
   190   }
   191 
   191 
   192   {
   192   {
   193     GridGraph g(5, 6);
   193     GridGraph g(5, 6);