alpar@906: /* -*- C++ -*- alpar@921: * src/test/test_tools.h - Part of LEMON, a generic C++ optimization library alpar@906: * alpar@906: * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@906: * (Egervary Combinatorial Optimization Research Group, EGRES). alpar@906: * alpar@906: * Permission to use, modify and distribute this software is granted alpar@906: * provided that this copyright notice appears in all copies. For alpar@906: * precise terms see the accompanying LICENSE file. alpar@906: * alpar@906: * This software is provided "AS IS" with no warranty of any kind, alpar@906: * express or implied, and with no claim as to its suitability for any alpar@906: * purpose. alpar@906: * alpar@906: */ alpar@906: alpar@921: #ifndef LEMON_TEST_TEST_TOOLS_H alpar@921: #define LEMON_TEST_TEST_TOOLS_H alpar@574: klao@978: #include klao@978: #include klao@978: klao@978: #include klao@978: klao@978: using namespace lemon; klao@978: alpar@574: //! \ingroup misc alpar@574: //! \file alpar@574: //! \brief Some utility to write test programs. alpar@574: alpar@574: alpar@679: ///If \c rc is fail, writes an error message end exit. alpar@574: alpar@574: ///If \c rc is fail, writes an error message end exit. alpar@574: ///The error message contains the file name and the line number of the alpar@679: ///source code in a standard from, which makes it possible to go there alpar@574: ///using good source browsers like e.g. \c emacs. alpar@574: /// alpar@574: ///For example alpar@574: ///\code check(0==1,"This is obviously false.");\endcode will alpar@574: ///print this (and then exits). alpar@574: ///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim alpar@774: /// alpar@774: ///\todo It should be in \c error.h alpar@574: #define check(rc, msg) \ alpar@574: if(!(rc)) { \ alpar@574: std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \ alpar@574: exit(1); \ alpar@574: } else { } \ alpar@574: alpar@574: ///Structure returned by \ref addPetersen(). alpar@574: alpar@574: ///Structure returned by \ref addPetersen(). alpar@574: /// alpar@574: template struct PetStruct alpar@574: { alpar@825: ///Vector containing the outer nodes. alpar@825: std::vector outer; alpar@825: ///Vector containing the inner nodes. alpar@825: std::vector inner; alpar@825: ///Vector containing the edges of the inner circle. alpar@825: std::vector incir; alpar@825: ///Vector containing the edges of the outer circle. alpar@825: std::vector outcir; alpar@825: ///Vector containing the chord edges. alpar@825: std::vector chords; alpar@574: }; alpar@574: alpar@721: alpar@721: alpar@574: ///Adds a Petersen graph to \c G. alpar@574: alpar@574: ///Adds a Petersen graph to \c G. deba@937: ///\return The nodes and edges of the generated graph. alpar@721: alpar@721: template klao@946: PetStruct addPetersen(Graph &G,int num = 5) alpar@574: { alpar@574: PetStruct n; alpar@574: alpar@574: for(int i=0;i void bidirGraph(Graph &G) klao@946: { klao@946: typedef typename Graph::Edge Edge; klao@946: typedef typename Graph::EdgeIt EdgeIt; klao@946: klao@946: std::vector ee; klao@946: klao@946: for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e); klao@946: klao@946: for(typename std::vector::iterator p=ee.begin();p!=ee.end();p++) klao@946: G.addEdge(G.head(*p),G.tail(*p)); klao@946: } klao@946: klao@946: klao@946: /// \brief Checks the bidirectioned Petersen graph. klao@946: /// klao@946: /// Checks the bidirectioned Petersen graph. klao@946: /// klao@946: template void checkBidirPetersen(Graph &G, int num = 5) klao@946: { klao@946: typedef typename Graph::Node Node; klao@946: klao@946: typedef typename Graph::EdgeIt EdgeIt; klao@946: typedef typename Graph::NodeIt NodeIt; klao@946: klao@946: checkGraphNodeList(G, 2 * num); klao@946: checkGraphEdgeList(G, 6 * num); klao@946: klao@946: for(NodeIt n(G);n!=INVALID;++n) { klao@946: checkGraphInEdgeList(G, n, 3); klao@946: checkGraphOutEdgeList(G, n, 3); klao@946: } klao@946: } klao@946: deba@937: ///Structure returned by \ref addSymPetersen(). alpar@574: deba@937: ///Structure returned by \ref addSymPetersen(). deba@937: /// deba@937: template struct SymPetStruct deba@937: { deba@937: ///Vector containing the outer nodes. deba@937: std::vector outer; deba@937: ///Vector containing the inner nodes. deba@937: std::vector inner; deba@937: ///Vector containing the edges of the inner circle. deba@937: std::vector incir; deba@937: ///Vector containing the edges of the outer circle. deba@937: std::vector outcir; deba@937: ///Vector containing the chord edges. deba@937: std::vector chords; deba@937: }; deba@937: deba@937: ///Adds a Petersen graph to the symmetric \c G. deba@937: deba@937: ///Adds a Petersen graph to the symmetric \c G. deba@937: ///\return The nodes and edges of the generated graph. deba@937: deba@937: template deba@937: SymPetStruct addSymPetersen(Graph &G,int num=5) deba@937: { deba@937: SymPetStruct n; deba@937: deba@937: for(int i=0;i