src/test/graph_test.cc
author deba
Sun, 26 Sep 2004 21:43:38 +0000
changeset 909 6a22e0dfd453
parent 906 17f31d280385
child 919 6153d9cf78c6
permissions -rw-r--r--
New symmetric Graph concept.
New symmetric list and smart graph.
Symmetric Graph tests based on the Graph Tests.
     1 /* -*- C++ -*-
     2  * src/test/graph_test.cc - Part of HUGOlib, a generic C++ optimization library
     3  *
     4  * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     5  * (Egervary Combinatorial Optimization Research Group, EGRES).
     6  *
     7  * Permission to use, modify and distribute this software is granted
     8  * provided that this copyright notice appears in all copies. For
     9  * precise terms see the accompanying LICENSE file.
    10  *
    11  * This software is provided "AS IS" with no warranty of any kind,
    12  * express or implied, and with no claim as to its suitability for any
    13  * purpose.
    14  *
    15  */
    16 
    17 #include<iostream>
    18 #include<hugo/smart_graph.h>
    19 #include<hugo/skeletons/graph.h>
    20 #include<hugo/list_graph.h>
    21 #include<hugo/full_graph.h>
    22 
    23 #include"test_tools.h"
    24 #include"graph_test.h"
    25 
    26 /**
    27 \file
    28 This test makes consistency checks of list graph structures.
    29 
    30 G.addNode(), G.addEdge(), G.tail(), G.head()
    31 
    32 \todo Checks for empty graphs and isolated points.
    33 conversion.
    34 */
    35 
    36 using namespace hugo;
    37 
    38 template<class Graph> void bidirPetersen(Graph &G)
    39 {
    40   typedef typename Graph::Edge Edge;
    41   typedef typename Graph::EdgeIt EdgeIt;
    42   
    43   checkGraphEdgeList(G,15);
    44   
    45   std::vector<Edge> ee;
    46   
    47   for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
    48 
    49   for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
    50     G.addEdge(G.head(*p),G.tail(*p));
    51 }
    52 
    53 template<class Graph> void checkPetersen(Graph &G)
    54 {
    55   typedef typename Graph::Node Node;
    56 
    57   typedef typename Graph::EdgeIt EdgeIt;
    58   typedef typename Graph::NodeIt NodeIt;
    59 
    60   checkGraphNodeList(G,10);
    61   checkGraphEdgeList(G,30);
    62 
    63   for(NodeIt n(G);n!=INVALID;++n) {
    64     checkGraphInEdgeList(G,n,3);
    65     checkGraphOutEdgeList(G,n,3);
    66   }  
    67 }
    68 
    69 //Compile Graph
    70 template void hugo::checkCompileStaticGraph<skeleton::StaticGraph>
    71 (skeleton::StaticGraph &);
    72 
    73 template void hugo::checkCompileGraph<skeleton::ExtendableGraph>
    74 (skeleton::ExtendableGraph &);
    75 
    76 template void hugo::checkCompileErasableGraph<skeleton::ErasableGraph>
    77 (skeleton::ErasableGraph &);
    78 
    79 //Compile SmartGraph
    80 template void hugo::checkCompileGraph<SmartGraph>(SmartGraph &);
    81 template void hugo::checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);
    82 
    83 //Compile SymSmartGraph
    84 //template void hugo::checkCompileGraph<SymSmartGraph>(SymSmartGraph &);
    85 //template void hugo::checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &);
    86 
    87 //Compile ListGraph
    88 template void hugo::checkCompileGraph<ListGraph>(ListGraph &);
    89 template void hugo::checkCompileErasableGraph<ListGraph>(ListGraph &);
    90 template void hugo::checkCompileGraphFindEdge<ListGraph>(ListGraph &);
    91 
    92 
    93 //Compile SymListGraph
    94 //template void hugo::checkCompileGraph<SymListGraph>(SymListGraph &);
    95 //template void hugo::checkCompileErasableGraph<SymListGraph>(SymListGraph &);
    96 //template void hugo::checkCompileGraphFindEdge<SymListGraph>(SymListGraph &);
    97 
    98 //Compile FullGraph
    99 template void hugo::checkCompileStaticGraph<FullGraph>(FullGraph &);
   100 template void hugo::checkCompileGraphFindEdge<FullGraph>(FullGraph &);
   101 
   102 //Compile EdgeSet <ListGraph>
   103 template void hugo::checkCompileGraph<EdgeSet <ListGraph> >
   104 (EdgeSet <ListGraph> &);
   105 template void hugo::checkCompileGraphEraseEdge<EdgeSet <ListGraph> >
   106 (EdgeSet <ListGraph> &);
   107 template void hugo::checkCompileGraphFindEdge<EdgeSet <ListGraph> >
   108 (EdgeSet <ListGraph> &);
   109 
   110 //Compile EdgeSet <NodeSet>
   111 template void hugo::checkCompileGraph<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
   112 template void hugo::checkCompileGraphEraseEdge<EdgeSet <NodeSet> >
   113 (EdgeSet <NodeSet> &);
   114 template void hugo::checkCompileGraphFindEdge<EdgeSet <NodeSet> >
   115 (EdgeSet <NodeSet> &);
   116 
   117 
   118 int main() 
   119 {
   120   {
   121     SmartGraph G;
   122     addPetersen(G);
   123     bidirPetersen(G);
   124     checkPetersen(G);
   125   }
   126   {
   127     ListGraph G;
   128     addPetersen(G);
   129     bidirPetersen(G);
   130     checkPetersen(G);
   131   }
   132   {
   133     //    SymSmartGraph G;
   134     //    addPetersen(G);
   135     //    checkPetersen(G);
   136   }
   137   {
   138     //    SymListGraph G;
   139     //    addPetersen(G);
   140     //    checkPetersen(G);
   141   }
   142 
   143   ///\file
   144   ///\todo map tests.
   145   ///\todo copy constr tests.
   146 
   147   std::cout << __FILE__ ": All tests passed.\n";
   148 
   149   return 0;
   150 }