3 #include <lemon/bits/undir_graph_extender.h>
 
     4 #include <lemon/concept/undir_graph.h>
 
     5 #include <lemon/list_graph.h>
 
     6 #include <lemon/smart_graph.h>
 
     7 #include <lemon/full_graph.h>
 
     8 #include <lemon/grid_graph.h>
 
    10 #include <lemon/graph_utils.h>
 
    12 #include "test_tools.h"
 
    15 using namespace lemon;
 
    16 using namespace lemon::concept;
 
    18 void check_concepts() {
 
    19   typedef UndirGraphExtender<ListGraphBase> UndirListGraphBase;
 
    21   typedef IterableUndirGraphExtender<
 
    22     AlterableUndirGraphExtender<UndirListGraphBase> > IterableUndirListGraph;
 
    24   typedef MappableUndirGraphExtender<IterableUndirListGraph>
 
    25     MappableUndirListGraph;
 
    27   typedef ErasableUndirGraphExtender<
 
    28     ClearableUndirGraphExtender<
 
    29     ExtendableUndirGraphExtender<MappableUndirListGraph> > > Graph;
 
    31   checkConcept<BaseIterableUndirGraphConcept, Graph>();
 
    32   checkConcept<IterableUndirGraphConcept, Graph>();
 
    33   checkConcept<MappableUndirGraphConcept, Graph>();
 
    35   checkConcept<UndirGraph, Graph>();
 
    36   checkConcept<ErasableUndirGraph, Graph>();
 
    38   checkConcept<UndirGraph, UndirListGraph>();
 
    39   checkConcept<ErasableUndirGraph, UndirListGraph>();
 
    41   checkConcept<UndirGraph, UndirSmartGraph>();
 
    42   checkConcept<ExtendableUndirGraph, UndirSmartGraph>();
 
    44   checkConcept<UndirGraph, UndirFullGraph>();
 
    46   checkConcept<UndirGraph, UndirGraph>();
 
    48   checkConcept<UndirGraph, GridGraph>();
 
    51 template <typename Graph>
 
    52 void check_item_counts(Graph &g, int n, int e) {
 
    54   for (typename Graph::NodeIt it(g); it != INVALID; ++it) {
 
    58   check(nn == n, "Wrong node number.");
 
    59   check(countNodes(g) == n, "Wrong node number.");
 
    62   for (typename Graph::EdgeIt it(g); it != INVALID; ++it) {
 
    66   check(ee == 2*e, "Wrong edge number.");
 
    67   check(countEdges(g) == 2*e, "Wrong edge number.");
 
    70   for (typename Graph::UndirEdgeIt it(g); it != INVALID; ++it) {
 
    74   check(uee == e, "Wrong undir edge number.");
 
    75   check(countUndirEdges(g) == e, "Wrong undir edge number.");
 
    78 template <typename Graph>
 
    79 void print_items(Graph &g) {
 
    81   typedef typename Graph::NodeIt NodeIt;
 
    82   typedef typename Graph::UndirEdgeIt UEdgeIt;
 
    83   typedef typename Graph::EdgeIt EdgeIt;
 
    85   std::cout << "Nodes" << std::endl;
 
    87   for(NodeIt it(g); it!=INVALID; ++it, ++i) {
 
    88     std::cout << "  " << i << ": " << g.id(it) << std::endl;
 
    91   std::cout << "UndirEdge" << std::endl;
 
    93   for(UEdgeIt it(g); it!=INVALID; ++it, ++i) {
 
    94     std::cout << "  " << i << ": " << g.id(it) 
 
    95 	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
 
    99   std::cout << "Edge" << std::endl;
 
   101   for(EdgeIt it(g); it!=INVALID; ++it, ++i) {
 
   102     std::cout << "  " << i << ": " << g.id(it)
 
   103 	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
 
   109 template <typename Graph>
 
   112   typedef typename Graph::Node Node;
 
   113   typedef typename Graph::UndirEdge UEdge;
 
   114   typedef typename Graph::Edge Edge;
 
   115   typedef typename Graph::NodeIt NodeIt;
 
   116   typedef typename Graph::UndirEdgeIt UEdgeIt;
 
   117   typedef typename Graph::EdgeIt EdgeIt;
 
   121   check_item_counts(g,0,0);
 
   129     e1 = g.addEdge(n1, n2),
 
   130     e2 = g.addEdge(n2, n3);
 
   134   check_item_counts(g,3,2);
 
   137 void checkGridGraph(const GridGraph& g, int w, int h) {
 
   138   check(g.width() == w, "Wrong width");
 
   139   check(g.height() == h, "Wrong height");
 
   141   for (int i = 0; i < w; ++i) {
 
   142     for (int j = 0; j < h; ++j) {
 
   143       check(g.col(g(i, j)) == i, "Wrong col");
 
   144       check(g.row(g(i, j)) == j, "Wrong row");
 
   148   for (int i = 0; i < w; ++i) {
 
   149     for (int j = 0; j < h - 1; ++j) {
 
   150       check(g.source(g.down(g(i, j))) == g(i, j), "Wrong down");
 
   151       check(g.target(g.down(g(i, j))) == g(i, j + 1), "Wrong down");
 
   153     check(g.down(g(i, h - 1)) == INVALID, "Wrong down");
 
   156   for (int i = 0; i < w; ++i) {
 
   157     for (int j = 1; j < h; ++j) {
 
   158       check(g.source(g.up(g(i, j))) == g(i, j), "Wrong up");
 
   159       check(g.target(g.up(g(i, j))) == g(i, j - 1), "Wrong up");
 
   161     check(g.up(g(i, 0)) == INVALID, "Wrong up");
 
   164   for (int j = 0; j < h; ++j) {
 
   165     for (int i = 0; i < w - 1; ++i) {
 
   166       check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right");
 
   167       check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right");      
 
   169     check(g.right(g(w - 1, j)) == INVALID, "Wrong right");    
 
   172   for (int j = 0; j < h; ++j) {
 
   173     for (int i = 1; i < w; ++i) {
 
   174       check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left");
 
   175       check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left");      
 
   177     check(g.left(g(0, j)) == INVALID, "Wrong left");    
 
   184   check_graph<UndirListGraph>();
 
   185   check_graph<UndirSmartGraph>();
 
   189     check_item_counts(g, 5, 10);
 
   194     check_item_counts(g, 30, 49);
 
   195     checkGridGraph(g, 5, 6);
 
   198   std::cout << __FILE__ ": All tests passed.\n";