# HG changeset patch # User Peter Kovacs # Date 1213560323 -7200 # Node ID 02f4d5d9bfd743e5737320a9f40fa964332bf953 # Parent 91fb4372688f290d0d71656c8175582cfee0de6f 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. diff -r 91fb4372688f -r 02f4d5d9bfd7 test/CMakeLists.txt --- a/test/CMakeLists.txt Sun Jun 15 22:03:33 2008 +0200 +++ b/test/CMakeLists.txt Sun Jun 15 22:05:23 2008 +0200 @@ -11,10 +11,11 @@ dim_test error_test graph_test + graph_utils_test kruskal_test maps_test + path_test random_test - path_test time_measure_test unionfind_test) diff -r 91fb4372688f -r 02f4d5d9bfd7 test/Makefile.am --- a/test/Makefile.am Sun Jun 15 22:03:33 2008 +0200 +++ b/test/Makefile.am Sun Jun 15 22:05:23 2008 +0200 @@ -2,10 +2,9 @@ test/CMakeLists.txt noinst_HEADERS += \ - test/digraph_test.h \ - test/graph_utils_test.h \ + test/graph_test.h \ test/heap_test.h \ - test/map_test.h \ + test/graph_maps_test.h \ test/test_tools.h check_PROGRAMS += \ diff -r 91fb4372688f -r 02f4d5d9bfd7 test/bfs_test.cc --- a/test/bfs_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/bfs_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -16,32 +16,25 @@ * */ -#include "test_tools.h" -//#include +#include +#include #include #include #include -#include + +#include "graph_test.h" +#include "test_tools.h" using namespace lemon; -const int PET_SIZE =5; - - -void check_Bfs_Compile() +void checkBfsCompile() { typedef concepts::Digraph Digraph; - - typedef Digraph::Arc Arc; - typedef Digraph::Node Node; - typedef Digraph::ArcIt ArcIt; - typedef Digraph::NodeIt NodeIt; - typedef Bfs BType; Digraph G; - Node n; - Arc e; + Digraph::Node n; + Digraph::Arc e; int l; bool b; BType::DistMap d(G); @@ -63,16 +56,12 @@ Path pp = bfs_test.path(n); } -void check_Bfs_Function_Compile() +void checkBfsFunctionCompile() { typedef int VType; typedef concepts::Digraph Digraph; - typedef Digraph::Arc Arc; typedef Digraph::Node Node; - typedef Digraph::ArcIt ArcIt; - typedef Digraph::NodeIt NodeIt; - typedef concepts::ReadMap LengthMap; Digraph g; bfs(g,Node()).run(); @@ -83,24 +72,15 @@ .reachedMap(concepts::ReadWriteMap()) .processedMap(concepts::WriteMap()) .run(Node()); - } -int main() -{ - - // typedef SmartDigraph Digraph; - typedef ListDigraph Digraph; - - typedef Digraph::Arc Arc; - typedef Digraph::Node Node; - typedef Digraph::ArcIt ArcIt; - typedef Digraph::NodeIt NodeIt; - typedef Digraph::ArcMap LengthMap; +template +void checkBfs() { + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); Digraph G; Node s, t; - PetStruct ps = addPetersen(G,PET_SIZE); + PetStruct ps = addPetersen(G, 5); s=ps.outer[2]; t=ps.inner[0]; @@ -108,10 +88,10 @@ Bfs bfs_test(G); bfs_test.run(s); - check(bfs_test.dist(t)==3,"Bfs found a wrong path. " << bfs_test.dist(t)); + check(bfs_test.dist(t)==3,"Bfs found a wrong path." << bfs_test.dist(t)); Path p = bfs_test.path(t); - check(p.length()==3,"getPath() found a wrong path."); + check(p.length()==3,"path() found a wrong path."); check(checkPath(G, p),"path() found a wrong path."); check(pathSource(G, p) == s,"path() found a wrong path."); check(pathTarget(G, p) == t,"path() found a wrong path."); @@ -139,3 +119,9 @@ } } +int main() +{ + checkBfs(); + checkBfs(); + return 0; +} diff -r 91fb4372688f -r 02f4d5d9bfd7 test/counter_test.cc --- a/test/counter_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/counter_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -17,50 +17,75 @@ */ #include +#include -///\file \brief Test cases for time_measure.h -/// -///\todo To be extended +using namespace lemon; +template +void bubbleSort(std::vector& v) { + Counter op("Bubble Sort - Operations: "); + Counter::NoSubCounter as(op, "Assignments: "); + Counter::NoSubCounter co(op, "Comparisons: "); + for (int i = v.size()-1; i > 0; --i) { + for (int j = 0; j < i; ++j) { + if (v[j] > v[j+1]) { + T tmp = v[j]; + v[j] = v[j+1]; + v[j+1] = tmp; + as += 3; + } + ++co; + } + } +} -int fibonacci(int f) -{ - static lemon::Counter count("Fibonacci steps: "); - count++; - if(f<1) return 0; - else if(f==1) return 1; - else return fibonacci(f-1)+fibonacci(f-2); +template +void insertionSort(std::vector& v) { + Counter op("Insertion Sort - Operations: "); + Counter::NoSubCounter as(op, "Assignments: "); + Counter::NoSubCounter co(op, "Comparisons: "); + for (int i = 1; i < int(v.size()); ++i) { + T value = v[i]; + ++as; + int j = i; + while (j > 0 && v[j-1] > value) { + v[j] = v[j-1]; + --j; + ++co; ++as; + } + v[j] = value; + ++as; + } +} + +template +void counterTest() { + MyCounter c("Main Counter: "); + c++; + typename MyCounter::SubCounter d(c, "SubCounter: "); + d++; + typename MyCounter::SubCounter::NoSubCounter e(d, "SubSubCounter: "); + e++; + d+=3; + c-=4; + e-=2; + c.reset(2); + c.reset(); +} + +void init(std::vector& v) { + v[0] = 10; v[1] = 60; v[2] = 20; v[3] = 90; v[4] = 100; + v[5] = 80; v[6] = 40; v[7] = 30; v[8] = 50; v[9] = 70; } int main() { - fibonacci(10); + counterTest(); + counterTest(); - { - typedef lemon::Counter MyCounter; - MyCounter c("Main counter: "); - c++; - c++; - MyCounter::SubCounter d(c,"Subcounter: "); - d++; - d++; - MyCounter::SubCounter::SubCounter e(d,"SubSubCounter: "); - e++; - e++; - } - - { - typedef lemon::NoCounter MyCounter; - MyCounter c("Main counter: "); - c++; - c++; - MyCounter::SubCounter d(c,"Subcounter: "); - d++; - d++; - MyCounter::SubCounter::SubCounter e(d,"SubSubCounter: "); - e++; - e++; - } + std::vector x(10); + init(x); bubbleSort(x); + init(x); insertionSort(x); return 0; } diff -r 91fb4372688f -r 02f4d5d9bfd7 test/dfs_test.cc --- a/test/dfs_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/dfs_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -16,32 +16,25 @@ * */ -#include "test_tools.h" -// #include +#include +#include #include #include #include -#include + +#include "graph_test.h" +#include "test_tools.h" using namespace lemon; -const int PET_SIZE =5; - - -void check_Dfs_SmartDigraph_Compile() +void checkDfsCompile() { typedef concepts::Digraph Digraph; - - typedef Digraph::Arc Arc; - typedef Digraph::Node Node; - typedef Digraph::ArcIt ArcIt; - typedef Digraph::NodeIt NodeIt; - typedef Dfs DType; Digraph G; - Node n; - Arc e; + Digraph::Node n; + Digraph::Arc e; int l; bool b; DType::DistMap d(G); @@ -63,17 +56,12 @@ Path pp = dfs_test.path(n); } - -void check_Dfs_Function_Compile() +void checkDfsFunctionCompile() { typedef int VType; typedef concepts::Digraph Digraph; - typedef Digraph::Arc Arc; typedef Digraph::Node Node; - typedef Digraph::ArcIt ArcIt; - typedef Digraph::NodeIt NodeIt; - typedef concepts::ReadMap LengthMap; Digraph g; dfs(g,Node()).run(); @@ -83,25 +71,16 @@ .distMap(concepts::WriteMap()) .reachedMap(concepts::ReadWriteMap()) .processedMap(concepts::WriteMap()) - .run(Node()); - + .run(Node()); } -int main() -{ - - // typedef SmartDigraph Digraph; - typedef ListDigraph Digraph; - - typedef Digraph::Arc Arc; - typedef Digraph::Node Node; - typedef Digraph::ArcIt ArcIt; - typedef Digraph::NodeIt NodeIt; - typedef Digraph::ArcMap LengthMap; +template +void checkDfs() { + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); Digraph G; Node s, t; - PetStruct ps = addPetersen(G,PET_SIZE); + PetStruct ps = addPetersen(G, 5); s=ps.outer[2]; t=ps.inner[0]; @@ -110,7 +89,7 @@ dfs_test.run(s); Path p = dfs_test.path(t); - check(p.length()==dfs_test.dist(t),"path() found a wrong path."); + check(p.length() == dfs_test.dist(t),"path() found a wrong path."); check(checkPath(G, p),"path() found a wrong path."); check(pathSource(G, p) == s,"path() found a wrong path."); check(pathTarget(G, p) == t,"path() found a wrong path."); @@ -128,3 +107,9 @@ } } +int main() +{ + checkDfs(); + checkDfs(); + return 0; +} diff -r 91fb4372688f -r 02f4d5d9bfd7 test/digraph_test.cc --- a/test/digraph_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/digraph_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -16,26 +16,21 @@ * */ -#include -#include - #include #include -//#include +#include //#include //#include #include "test_tools.h" -#include "digraph_test.h" -#include "map_test.h" - +#include "graph_test.h" +#include "graph_maps_test.h" using namespace lemon; using namespace lemon::concepts; - -int main() { - { // checking digraph components +void check_concepts() { + { // Checking digraph components checkConcept(); checkConcept, @@ -46,37 +41,104 @@ checkConcept, MappableDigraphComponent<> >(); - } - { // checking skeleton digraphs + { // Checking skeleton digraph checkConcept(); } - { // checking list digraph - checkConcept(); + { // Checking ListDigraph + checkConcept(); checkConcept, ListDigraph>(); checkConcept, ListDigraph>(); checkConcept, ListDigraph>(); checkConcept, ListDigraph>(); + checkDigraphIterators(); + } + { // Checking SmartDigraph + checkConcept(); + checkConcept, SmartDigraph>(); + checkConcept, SmartDigraph>(); + checkConcept, SmartDigraph>(); + checkDigraphIterators(); + } +// { // Checking FullDigraph +// checkConcept(); +// checkDigraphIterators(); +// } +// { // Checking HyperCubeDigraph +// checkConcept(); +// checkDigraphIterators(); +// } +} +template +void check_graph_validity() { + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); + Digraph g; + + Node + n1 = g.addNode(), + n2 = g.addNode(), + n3 = g.addNode(); + + Arc + e1 = g.addArc(n1, n2), + e2 = g.addArc(n2, n3); + + check(g.valid(n1), "Wrong validity check"); + check(g.valid(e1), "Wrong validity check"); + + check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); + check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); +} + +template +void check_graph_validity_erase() { + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); + Digraph g; + + Node + n1 = g.addNode(), + n2 = g.addNode(), + n3 = g.addNode(); + + Arc + e1 = g.addArc(n1, n2), + e2 = g.addArc(n2, n3); + + check(g.valid(n1), "Wrong validity check"); + check(g.valid(e1), "Wrong validity check"); + + g.erase(n1); + + check(!g.valid(n1), "Wrong validity check"); + check(g.valid(n2), "Wrong validity check"); + check(g.valid(n3), "Wrong validity check"); + check(!g.valid(e1), "Wrong validity check"); + check(g.valid(e2), "Wrong validity check"); + + check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); + check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); +} + +void check_digraphs() { + { // Checking ListDigraph checkDigraph(); checkGraphNodeMap(); checkGraphArcMap(); + + check_graph_validity_erase(); } -// { // checking smart digraph -// checkConcept(); + { // Checking SmartDigraph + checkDigraph(); + checkGraphNodeMap(); + checkGraphArcMap(); -// checkDigraph(); -// checkDigraphNodeMap(); -// checkDigraphArcMap(); -// } -// { // checking full digraph -// checkConcept(); -// } -// { // checking full digraph -// checkConcept(); -// } + check_graph_validity(); + } +} - std::cout << __FILE__ ": All tests passed.\n"; - +int main() { + check_concepts(); + check_digraphs(); return 0; } diff -r 91fb4372688f -r 02f4d5d9bfd7 test/digraph_test.h --- a/test/digraph_test.h Sun Jun 15 22:03:33 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,188 +0,0 @@ -/* -*- C++ -*- - * - * This file is a part of LEMON, a generic C++ optimization library - * - * Copyright (C) 2003-2008 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport - * (Egervary Research Group on Combinatorial Optimization, EGRES). - * - * Permission to use, modify and distribute this software is granted - * provided that this copyright notice appears in all copies. For - * precise terms see the accompanying LICENSE file. - * - * This software is provided "AS IS" with no warranty of any kind, - * express or implied, and with no claim as to its suitability for any - * purpose. - * - */ - -#ifndef LEMON_TEST_GRAPH_TEST_H -#define LEMON_TEST_GRAPH_TEST_H - -//#include -#include "test_tools.h" - -//! \ingroup misc -//! \file -//! \brief Some utility and test cases to test digraph classes. -namespace lemon { - - ///Structure returned by \ref addPetersen(). - - ///Structure returned by \ref addPetersen(). - /// - template - struct PetStruct - { - ///Vector containing the outer nodes. - std::vector outer; - ///Vector containing the inner nodes. - std::vector inner; - ///Vector containing the edges of the inner circle. - std::vector incir; - ///Vector containing the edges of the outer circle. - std::vector outcir; - ///Vector containing the chord edges. - std::vector chords; - }; - - - - ///Adds a Petersen graph to \c G. - - ///Adds a Petersen graph to \c G. - ///\return The nodes and edges of the generated graph. - - template - PetStruct addPetersen(Digraph &G,int num = 5) - { - PetStruct n; - - for(int i=0;i - void bidirDigraph(Digraph &G) - { - typedef typename Digraph::Arc Arc; - typedef typename Digraph::ArcIt ArcIt; - - std::vector ee; - - for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e); - - for(typename std::vector::iterator p=ee.begin();p!=ee.end();p++) - G.addArc(G.target(*p),G.source(*p)); - } - - - /// \brief Checks the bidirectioned Petersen graph. - /// - /// Checks the bidirectioned Petersen graph. - /// - template - void checkBidirPetersen(Digraph &G, int num = 5) - { - typedef typename Digraph::Node Node; - - typedef typename Digraph::ArcIt ArcIt; - typedef typename Digraph::NodeIt NodeIt; - - checkDigraphNodeList(G, 2 * num); - checkDigraphArcList(G, 6 * num); - - for(NodeIt n(G);n!=INVALID;++n) { - checkDigraphInArcList(G, n, 3); - checkDigraphOutArcList(G, n, 3); - } - } - - template void checkDigraphNodeList(Digraph &G, int nn) - { - typename Digraph::NodeIt n(G); - for(int i=0;i - void checkDigraphArcList(Digraph &G, int nn) - { - typedef typename Digraph::ArcIt ArcIt; - - ArcIt e(G); - for(int i=0;i - void checkDigraphOutArcList(Digraph &G, typename Digraph::Node n, int nn) - { - typename Digraph::OutArcIt e(G,n); - for(int i=0;i void - checkDigraphInArcList(Digraph &G, typename Digraph::Node n, int nn) - { - typename Digraph::InArcIt e(G,n); - for(int i=0;i - void checkDigraph() { - const int num = 5; - Digraph G; - addPetersen(G, num); - bidirDigraph(G); - checkBidirPetersen(G, num); - } - - template - void checkDigraphIterators(const Digraph& digraph) { - typedef typename Digraph::Node Node; - typedef typename Digraph::NodeIt NodeIt; - typedef typename Digraph::Arc Arc; - typedef typename Digraph::ArcIt ArcIt; - typedef typename Digraph::InArcIt InArcIt; - typedef typename Digraph::OutArcIt OutArcIt; - // typedef ConArcIt ConArcIt; - } - - ///\file - ///\todo Check target(), source() as well; - - -} //namespace lemon - - -#endif diff -r 91fb4372688f -r 02f4d5d9bfd7 test/dijkstra_test.cc --- a/test/dijkstra_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/dijkstra_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -16,9 +16,6 @@ * */ -///\file -///\brief Test cases for Dijkstra algorithm. - #include #include #include @@ -26,6 +23,7 @@ #include #include +#include "graph_test.h" #include "test_tools.h" using namespace lemon; diff -r 91fb4372688f -r 02f4d5d9bfd7 test/dim_test.cc --- a/test/dim_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/dim_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -25,63 +25,59 @@ int main() { - cout << "Testing classes 'dim2::Point' and 'dim2::BoundingBox'." << endl; - typedef dim2::Point Point; Point p; - check(p.size()==2, "Wrong vector initialization."); + check(p.size()==2, "Wrong dim2::Point initialization."); Point a(1,2); Point b(3,4); - check(a[0]==1 && a[1]==2, "Wrong vector initialization."); + check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization."); p = a+b; - check(p.x==4 && p.y==6, "Wrong vector addition."); + check(p.x==4 && p.y==6, "Wrong dim2::Point addition."); p = a-b; - check(p.x==-2 && p.y==-2, "Wrong vector subtraction."); + check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction."); - check(a.normSquare()==5,"Wrong vector norm calculation."); - check(a*b==11, "Wrong vector scalar product."); + check(a.normSquare()==5,"Wrong dim2::Point norm calculation."); + check(a*b==11, "Wrong dim2::Point scalar product."); int l=2; p = a*l; - check(p.x==2 && p.y==4, "Wrong vector multiplication by a scalar."); + check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar."); p = b/l; - check(p.x==1 && p.y==2, "Wrong vector division by a scalar."); + check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar."); typedef dim2::BoundingBox BB; BB box1; - check(box1.empty(), "It should be empty."); + check(box1.empty(), "Wrong empty() in dim2::BoundingBox."); box1.add(a); - check(!box1.empty(), "It should not be empty."); + check(!box1.empty(), "Wrong empty() in dim2::BoundingBox."); box1.add(b); check(box1.bottomLeft().x==1 && box1.bottomLeft().y==2 && box1.topRight().x==3 && box1.topRight().y==4, - "Wrong addition of points to box."); + "Wrong addition of points to dim2::BoundingBox."); p.x=2; p.y=3; - check(box1.inside(p), "It should be inside."); + check(box1.inside(p), "Wrong inside() in dim2::BoundingBox."); p.x=1; p.y=3; - check(box1.inside(p), "It should be inside."); + check(box1.inside(p), "Wrong inside() in dim2::BoundingBox."); p.x=0; p.y=3; - check(!box1.inside(p), "It should not be inside."); + check(!box1.inside(p), "Wrong inside() in dim2::BoundingBox."); BB box2(p); - check(!box2.empty(), - "It should not be empty. Constructed from 1 point."); + check(!box2.empty(), "Wrong empty() in dim2::BoundingBox."); box2.add(box1); - check(box2.inside(p), - "It should be inside. Incremented a box with another one."); + check(box2.inside(p), "Wrong inside() in dim2::BoundingBox."); return 0; } diff -r 91fb4372688f -r 02f4d5d9bfd7 test/error_test.cc --- a/test/error_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/error_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -54,6 +54,7 @@ } #undef LEMON_DISABLE_ASSERTS +//checking custom assert handler #define LEMON_ASSERT_CUSTOM static int cnt = 0; diff -r 91fb4372688f -r 02f4d5d9bfd7 test/graph_maps_test.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/graph_maps_test.h Sun Jun 15 22:05:23 2008 +0200 @@ -0,0 +1,144 @@ +/* -*- C++ -*- + * + * This file is a part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2003-2008 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#ifndef LEMON_TEST_MAP_TEST_H +#define LEMON_TEST_MAP_TEST_H + +#include +#include + +#include "test_tools.h" + +namespace lemon { + + template + void checkGraphNodeMap() { + Graph graph; + const int num = 16; + + typedef typename Graph::Node Node; + + std::vector nodes; + for (int i = 0; i < num; ++i) { + nodes.push_back(graph.addNode()); + } + typedef typename Graph::template NodeMap IntNodeMap; + IntNodeMap map(graph, 42); + for (int i = 0; i < int(nodes.size()); ++i) { + check(map[nodes[i]] == 42, "Wrong map constructor."); + } + for (int i = 0; i < num; ++i) { + nodes.push_back(graph.addNode()); + map[nodes.back()] = 23; + check(map[nodes.back()] == 23, "Wrong operator[]."); + } + map = constMap(12); + for (int i = 0; i < int(nodes.size()); ++i) { + check(map[nodes[i]] == 12, "Wrong map constructor."); + } + graph.clear(); + nodes.clear(); + } + + template + void checkGraphArcMap() { + Graph graph; + const int num = 16; + + typedef typename Graph::Node Node; + typedef typename Graph::Arc Arc; + + std::vector nodes; + for (int i = 0; i < num; ++i) { + nodes.push_back(graph.addNode()); + } + + std::vector arcs; + for (int i = 0; i < num; ++i) { + for (int j = 0; j < i; ++j) { + arcs.push_back(graph.addArc(nodes[i], nodes[j])); + } + } + + typedef typename Graph::template ArcMap IntArcMap; + IntArcMap map(graph, 42); + + for (int i = 0; i < int(arcs.size()); ++i) { + check(map[arcs[i]] == 42, "Wrong map constructor."); + } + + for (int i = 0; i < num; ++i) { + for (int j = i + 1; j < num; ++j) { + arcs.push_back(graph.addArc(nodes[i], nodes[j])); + map[arcs.back()] = 23; + check(map[arcs.back()] == 23, "Wrong operator[]."); + } + } + map = constMap(12); + for (int i = 0; i < int(arcs.size()); ++i) { + check(map[arcs[i]] == 12, "Wrong map constructor."); + } + graph.clear(); + arcs.clear(); + } + + template + void checkGraphEdgeMap() { + Graph graph; + const int num = 16; + + typedef typename Graph::Node Node; + typedef typename Graph::Edge Edge; + + std::vector nodes; + for (int i = 0; i < num; ++i) { + nodes.push_back(graph.addNode()); + } + + std::vector edges; + for (int i = 0; i < num; ++i) { + for (int j = 0; j < i; ++j) { + edges.push_back(graph.addEdge(nodes[i], nodes[j])); + } + } + + typedef typename Graph::template EdgeMap IntEdgeMap; + IntEdgeMap map(graph, 42); + + for (int i = 0; i < int(edges.size()); ++i) { + check(map[edges[i]] == 42, "Wrong map constructor."); + } + + for (int i = 0; i < num; ++i) { + for (int j = i + 1; j < num; ++j) { + edges.push_back(graph.addEdge(nodes[i], nodes[j])); + map[edges.back()] = 23; + check(map[edges.back()] == 23, "Wrong operator[]."); + } + } + map = constMap(12); + for (int i = 0; i < int(edges.size()); ++i) { + check(map[edges[i]] == 12, "Wrong map constructor."); + } + graph.clear(); + edges.clear(); + } + +} + +#endif diff -r 91fb4372688f -r 02f4d5d9bfd7 test/graph_test.cc --- a/test/graph_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/graph_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -22,17 +22,15 @@ // #include // #include -#include - #include "test_tools.h" - +#include "graph_test.h" +#include "graph_maps_test.h" using namespace lemon; using namespace lemon::concepts; void check_concepts() { - - { // checking digraph components + { // Checking graph components checkConcept(); checkConcept, @@ -43,52 +41,40 @@ checkConcept, MappableGraphComponent<> >(); - } - { - checkConcept(); - checkConcept(); -// checkConcept(); -// checkConcept(); -// checkConcept(); + { // Checking skeleton graph + checkConcept(); } + { // Checking ListGraph + checkConcept(); + checkConcept, ListGraph>(); + checkConcept, ListGraph>(); + checkConcept, ListGraph>(); + checkConcept, ListGraph>(); + checkGraphIterators(); + } + { // Checking SmartGraph + checkConcept(); + checkConcept, SmartGraph>(); + checkConcept, SmartGraph>(); + checkConcept, SmartGraph>(); + checkGraphIterators(); + } +// { // Checking FullGraph +// checkConcept(); +// checkGraphIterators(); +// } +// { // Checking GridGraph +// checkConcept(); +// checkGraphIterators(); +// } } template -void check_item_counts(Graph &g, int n, int e) { - int nn = 0; - for (typename Graph::NodeIt it(g); it != INVALID; ++it) { - ++nn; - } - - check(nn == n, "Wrong node number."); - // check(countNodes(g) == n, "Wrong node number."); - - int ee = 0; - for (typename Graph::ArcIt it(g); it != INVALID; ++it) { - ++ee; - } - - check(ee == 2*e, "Wrong arc number."); - // check(countArcs(g) == 2*e, "Wrong arc number."); - - int uee = 0; - for (typename Graph::EdgeIt it(g); it != INVALID; ++it) { - ++uee; - } - - check(uee == e, "Wrong edge number."); - // check(countEdges(g) == e, "Wrong edge number."); -} - -template -void check_graph_counts() { - +void check_graph_validity() { TEMPLATE_GRAPH_TYPEDEFS(Graph); Graph g; - check_item_counts(g,0,0); - Node n1 = g.addNode(), n2 = g.addNode(), @@ -98,17 +84,20 @@ e1 = g.addEdge(n1, n2), e2 = g.addEdge(n2, n3); - check_item_counts(g,3,2); + check(g.valid(n1), "Wrong validity check"); + check(g.valid(e1), "Wrong validity check"); + check(g.valid(g.direct(e1, true)), "Wrong validity check"); + + check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); + check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); + check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); } template -void check_graph_validity() { - +void check_graph_validity_erase() { TEMPLATE_GRAPH_TYPEDEFS(Graph); Graph g; - check_item_counts(g,0,0); - Node n1 = g.addNode(), n2 = g.addNode(), @@ -118,53 +107,23 @@ e1 = g.addEdge(n1, n2), e2 = g.addEdge(n2, n3); - check(g.valid(n1), "Validity check"); - check(g.valid(e1), "Validity check"); - check(g.valid(g.direct(e1, true)), "Validity check"); - - check(!g.valid(g.nodeFromId(-1)), "Validity check"); - check(!g.valid(g.edgeFromId(-1)), "Validity check"); - check(!g.valid(g.arcFromId(-1)), "Validity check"); - -} - -template -void check_graph_validity_erase() { - - TEMPLATE_GRAPH_TYPEDEFS(Graph); - Graph g; - - check_item_counts(g,0,0); - - Node - n1 = g.addNode(), - n2 = g.addNode(), - n3 = g.addNode(); - - Edge - e1 = g.addEdge(n1, n2), - e2 = g.addEdge(n2, n3); - - check(g.valid(n1), "Validity check"); - check(g.valid(e1), "Validity check"); - check(g.valid(g.direct(e1, true)), "Validity check"); + check(g.valid(n1), "Wrong validity check"); + check(g.valid(e1), "Wrong validity check"); + check(g.valid(g.direct(e1, true)), "Wrong validity check"); g.erase(n1); - check(!g.valid(n1), "Validity check"); - check(g.valid(n2), "Validity check"); - check(g.valid(n3), "Validity check"); - check(!g.valid(e1), "Validity check"); - check(g.valid(e2), "Validity check"); + check(!g.valid(n1), "Wrong validity check"); + check(g.valid(n2), "Wrong validity check"); + check(g.valid(n3), "Wrong validity check"); + check(!g.valid(e1), "Wrong validity check"); + check(g.valid(e2), "Wrong validity check"); - check(!g.valid(g.nodeFromId(-1)), "Validity check"); - check(!g.valid(g.edgeFromId(-1)), "Validity check"); - check(!g.valid(g.arcFromId(-1)), "Validity check"); - + check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); + check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); + check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); } - - // void checkGridGraph(const GridGraph& g, int w, int h) { // check(g.width() == w, "Wrong width"); // check(g.height() == h, "Wrong height"); @@ -209,27 +168,36 @@ // } // } +void check_graphs() { + { // Checking ListGraph + checkGraph(); + checkGraphNodeMap(); + checkGraphEdgeMap(); + + check_graph_validity_erase(); + } + { // Checking SmartGraph + checkGraph(); + checkGraphNodeMap(); + checkGraphEdgeMap(); + + check_graph_validity(); + } +// { // Checking FullGraph +// FullGraph g(5); +// checkGraphNodeList(g, 5); +// checkGraphEdgeList(g, 10); +// } +// { // Checking GridGraph +// GridGraph g(5, 6); +// checkGraphNodeList(g, 30); +// checkGraphEdgeList(g, 49); +// checkGridGraph(g, 5, 6); +// } +} + int main() { check_concepts(); - - check_graph_counts(); - check_graph_counts(); - - check_graph_validity_erase(); - check_graph_validity(); - -// { -// FullGraph g(5); -// check_item_counts(g, 5, 10); -// } - -// { -// GridGraph g(5, 6); -// check_item_counts(g, 30, 49); -// checkGridGraph(g, 5, 6); -// } - - std::cout << __FILE__ ": All tests passed.\n"; - + check_graphs(); return 0; } diff -r 91fb4372688f -r 02f4d5d9bfd7 test/graph_test.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/graph_test.h Sun Jun 15 22:05:23 2008 +0200 @@ -0,0 +1,262 @@ +/* -*- C++ -*- + * + * This file is a part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2003-2008 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#ifndef LEMON_TEST_GRAPH_TEST_H +#define LEMON_TEST_GRAPH_TEST_H + +#include +#include "test_tools.h" + +namespace lemon { + + template + void checkGraphNodeList(const Graph &G, int cnt) + { + typename Graph::NodeIt n(G); + for(int i=0;i + void checkGraphArcList(const Graph &G, int cnt) + { + typename Graph::ArcIt e(G); + for(int i=0;i + void checkGraphOutArcList(const Graph &G, typename Graph::Node n, int cnt) + { + typename Graph::OutArcIt e(G,n); + for(int i=0;i + void checkGraphInArcList(const Graph &G, typename Graph::Node n, int cnt) + { + typename Graph::InArcIt e(G,n); + for(int i=0;i + void checkGraphEdgeList(const Graph &G, int cnt) + { + typename Graph::EdgeIt e(G); + for(int i=0;i + void checkGraphIncEdgeList(const Graph &G, typename Graph::Node n, int cnt) + { + typename Graph::IncEdgeIt e(G,n); + for(int i=0;i + void checkDigraphIterators() { + typedef typename Digraph::Node Node; + typedef typename Digraph::NodeIt NodeIt; + typedef typename Digraph::Arc Arc; + typedef typename Digraph::ArcIt ArcIt; + typedef typename Digraph::InArcIt InArcIt; + typedef typename Digraph::OutArcIt OutArcIt; + } + + template + void checkGraphIterators() { + checkDigraphIterators(); + typedef typename Graph::Edge Edge; + typedef typename Graph::EdgeIt EdgeIt; + typedef typename Graph::IncEdgeIt IncEdgeIt; + } + + // Structure returned by addPetersen() + template + struct PetStruct + { + // Vector containing the outer nodes + std::vector outer; + // Vector containing the inner nodes + std::vector inner; + // Vector containing the arcs of the inner circle + std::vector incir; + // Vector containing the arcs of the outer circle + std::vector outcir; + // Vector containing the chord arcs + std::vector chords; + }; + + // Adds the reverse pair of all arcs to a digraph + template + void bidirDigraph(Digraph &G) + { + typedef typename Digraph::Arc Arc; + typedef typename Digraph::ArcIt ArcIt; + + std::vector ee; + + for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e); + + for(int i=0;i + PetStruct addPetersen(Digraph &G,int num = 5) + { + PetStruct n; + + for(int i=0;i + void checkBidirPetersen(const Digraph &G, int num = 5) + { + typedef typename Digraph::NodeIt NodeIt; + + checkGraphNodeList(G, 2 * num); + checkGraphArcList(G, 6 * num); + + for(NodeIt n(G);n!=INVALID;++n) { + checkGraphInArcList(G, n, 3); + checkGraphOutArcList(G, n, 3); + } + } + + // Structure returned by addUPetersen() + template + struct UPetStruct + { + // Vector containing the outer nodes + std::vector outer; + // Vector containing the inner nodes + std::vector inner; + // Vector containing the edges of the inner circle + std::vector incir; + // Vector containing the edges of the outer circle + std::vector outcir; + // Vector containing the chord edges + std::vector chords; + }; + + // Adds a Petersen graph to \c G. + // Returns the nodes and edges of the generated graph. + template + UPetStruct addUPetersen(Graph &G,int num=5) + { + UPetStruct n; + + for(int i=0;i + void checkUndirPetersen(const Graph &G, int num = 5) + { + typedef typename Graph::NodeIt NodeIt; + + checkGraphNodeList(G, 2 * num); + checkGraphEdgeList(G, 3 * num); + checkGraphArcList(G, 6 * num); + + for(NodeIt n(G);n!=INVALID;++n) { + checkGraphIncEdgeList(G, n, 3); + } + } + + template + void checkDigraph() { + const int num = 5; + Digraph G; + checkGraphNodeList(G, 0); + checkGraphArcList(G, 0); + addPetersen(G, num); + bidirDigraph(G); + checkBidirPetersen(G, num); + } + + template + void checkGraph() { + const int num = 5; + Graph G; + checkGraphNodeList(G, 0); + checkGraphEdgeList(G, 0); + addUPetersen(G, num); + checkUndirPetersen(G, num); + } + +} //namespace lemon + +#endif diff -r 91fb4372688f -r 02f4d5d9bfd7 test/graph_utils_test.cc --- a/test/graph_utils_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/graph_utils_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -16,41 +16,177 @@ * */ -#include -#include +#include +#include +#include #include - #include #include +#include "graph_test.h" #include "test_tools.h" -#include "graph_utils_test.h" - using namespace lemon; -template -void checkSnapDeg() +template +void checkFindArcs() { + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); + + { + Digraph digraph; + for (int i = 0; i < 10; ++i) { + digraph.addNode(); + } + DescriptorMap nodes(digraph); + typename DescriptorMap::InverseMap invNodes(nodes); + for (int i = 0; i < 100; ++i) { + int src = rnd[invNodes.size()]; + int trg = rnd[invNodes.size()]; + digraph.addArc(invNodes[src], invNodes[trg]); + } + typename Digraph::template ArcMap found(digraph, false); + DescriptorMap arcs(digraph); + for (NodeIt src(digraph); src != INVALID; ++src) { + for (NodeIt trg(digraph); trg != INVALID; ++trg) { + for (ConArcIt con(digraph, src, trg); con != INVALID; ++con) { + check(digraph.source(con) == src, "Wrong source."); + check(digraph.target(con) == trg, "Wrong target."); + check(found[con] == false, "The arc found already."); + found[con] = true; + } + } + } + for (ArcIt it(digraph); it != INVALID; ++it) { + check(found[it] == true, "The arc is not found."); + } + } + + { + int num = 5; + Digraph fg; + std::vector nodes; + for (int i = 0; i < num; ++i) { + nodes.push_back(fg.addNode()); + } + for (int i = 0; i < num * num; ++i) { + fg.addArc(nodes[i / num], nodes[i % num]); + } + check(countNodes(fg) == num, "Wrong node number."); + check(countArcs(fg) == num*num, "Wrong arc number."); + for (NodeIt src(fg); src != INVALID; ++src) { + for (NodeIt trg(fg); trg != INVALID; ++trg) { + ConArcIt con(fg, src, trg); + check(con != INVALID, "There is no connecting arc."); + check(fg.source(con) == src, "Wrong source."); + check(fg.target(con) == trg, "Wrong target."); + check(++con == INVALID, "There is more connecting arc."); + } + } + ArcLookUp al1(fg); + DynArcLookUp al2(fg); + AllArcLookUp al3(fg); + for (NodeIt src(fg); src != INVALID; ++src) { + for (NodeIt trg(fg); trg != INVALID; ++trg) { + Arc con1 = al1(src, trg); + Arc con2 = al2(src, trg); + Arc con3 = al3(src, trg); + Arc con4 = findArc(fg, src, trg); + check(con1 == con2 && con2 == con3 && con3 == con4, "Different results.") + check(con1 != INVALID, "There is no connecting arc."); + check(fg.source(con1) == src, "Wrong source."); + check(fg.target(con1) == trg, "Wrong target."); + check(al3(src, trg, con3) == INVALID, "There is more connecting arc."); + check(findArc(fg, src, trg, con4) == INVALID, "There is more connecting arc."); + } + } + } +} + +template +void checkFindEdges() { + TEMPLATE_GRAPH_TYPEDEFS(Graph); + Graph graph; + for (int i = 0; i < 10; ++i) { + graph.addNode(); + } + DescriptorMap nodes(graph); + typename DescriptorMap::InverseMap invNodes(nodes); + for (int i = 0; i < 100; ++i) { + int src = rnd[invNodes.size()]; + int trg = rnd[invNodes.size()]; + graph.addEdge(invNodes[src], invNodes[trg]); + } + typename Graph::template EdgeMap found(graph, 0); + DescriptorMap edges(graph); + for (NodeIt src(graph); src != INVALID; ++src) { + for (NodeIt trg(graph); trg != INVALID; ++trg) { + for (ConEdgeIt con(graph, src, trg); con != INVALID; ++con) { + check( (graph.u(con) == src && graph.v(con) == trg) || + (graph.v(con) == src && graph.u(con) == trg), "Wrong end nodes."); + ++found[con]; + check(found[con] <= 2, "The edge found more than twice."); + } + } + } + for (EdgeIt it(graph); it != INVALID; ++it) { + check( (graph.u(it) != graph.v(it) && found[it] == 2) || + (graph.u(it) == graph.v(it) && found[it] == 1), + "The edge is not found correctly."); + } +} + +template +void checkDeg() { - Graph g; - typename Graph::Node n1=g.addNode(); - typename Graph::Node n2=g.addNode(); - - InDegMap ind(g); - + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); + + const int nodeNum = 10; + const int arcNum = 100; + Digraph digraph; + InDegMap inDeg(digraph); + OutDegMap outDeg(digraph); + std::vector nodes(nodeNum); + for (int i = 0; i < nodeNum; ++i) { + nodes[i] = digraph.addNode(); + } + std::vector arcs(arcNum); + for (int i = 0; i < arcNum; ++i) { + arcs[i] = digraph.addArc(nodes[rnd[nodeNum]], nodes[rnd[nodeNum]]); + } + for (int i = 0; i < nodeNum; ++i) { + check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]), + "Wrong in degree map"); + } + for (int i = 0; i < nodeNum; ++i) { + check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]), + "Wrong out degree map"); + } +} + +template +void checkSnapDeg() +{ + TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); + + Digraph g; + Node n1=g.addNode(); + Node n2=g.addNode(); + + InDegMap ind(g); + g.addArc(n1,n2); - typename Graph::Snapshot snap(g); + typename Digraph::Snapshot snap(g); - OutDegMap outd(g); + OutDegMap outd(g); check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value."); check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value."); g.addArc(n1,n2); g.addArc(n2,n1); - + check(ind[n1]==1 && ind[n2]==2, "Wrong InDegMap value."); check(outd[n1]==2 && outd[n2]==1, "Wrong OutDegMap value."); @@ -58,84 +194,20 @@ check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value."); check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value."); - } int main() { - ///\file - { // checking list graph - checkDigraphCounters(); - checkFindArc(); - } - { // checking smart graph - checkDigraphCounters(); - checkFindArc(); - } - { - int num = 5; - SmartDigraph fg; - std::vector nodes; - for (int i = 0; i < num; ++i) { - nodes.push_back(fg.addNode()); - } - for (int i = 0; i < num * num; ++i) { - fg.addArc(nodes[i / num], nodes[i % num]); - } - check(countNodes(fg) == num, "FullGraph: wrong node number."); - check(countArcs(fg) == num*num, "FullGraph: wrong arc number."); - for (SmartDigraph::NodeIt src(fg); src != INVALID; ++src) { - for (SmartDigraph::NodeIt trg(fg); trg != INVALID; ++trg) { - ConArcIt con(fg, src, trg); - check(con != INVALID, "There is no connecting arc."); - check(fg.source(con) == src, "Wrong source."); - check(fg.target(con) == trg, "Wrong target."); - check(++con == INVALID, "There is more connecting arc."); - } - } - AllArcLookUp el(fg); - for (SmartDigraph::NodeIt src(fg); src != INVALID; ++src) { - for (SmartDigraph::NodeIt trg(fg); trg != INVALID; ++trg) { - SmartDigraph::Arc con = el(src, trg); - check(con != INVALID, "There is no connecting arc."); - check(fg.source(con) == src, "Wrong source."); - check(fg.target(con) == trg, "Wrong target."); - check(el(src,trg,con) == INVALID, "There is more connecting arc."); - } - } - } + // Checking ConArcIt, ConEdgeIt, ArcLookUp, AllArcLookUp, and DynArcLookUp + checkFindArcs(); + checkFindArcs(); + checkFindEdges(); + checkFindEdges(); - //check In/OutDegMap (and Snapshot feature) - + // Checking In/OutDegMap (and Snapshot feature) + checkDeg(); + checkDeg(); checkSnapDeg(); checkSnapDeg(); - - { - const int nodeNum = 10; - const int arcNum = 100; - ListDigraph digraph; - InDegMap inDeg(digraph); - OutDegMap outDeg(digraph); - std::vector nodes(nodeNum); - for (int i = 0; i < nodeNum; ++i) { - nodes[i] = digraph.addNode(); - } - std::vector arcs(arcNum); - for (int i = 0; i < arcNum; ++i) { - arcs[i] = - digraph.addArc(nodes[rnd[nodeNum]], nodes[rnd[nodeNum]]); - } - for (int i = 0; i < nodeNum; ++i) { - check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]), - "Wrong in degree map"); - } - for (int i = 0; i < nodeNum; ++i) { - check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]), - "Wrong in degree map"); - } - } - - ///Everything is OK - std::cout << __FILE__ ": All tests passed.\n"; return 0; } diff -r 91fb4372688f -r 02f4d5d9bfd7 test/graph_utils_test.h --- a/test/graph_utils_test.h Sun Jun 15 22:03:33 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/* -*- C++ -*- - * - * This file is a part of LEMON, a generic C++ optimization library - * - * Copyright (C) 2003-2008 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport - * (Egervary Research Group on Combinatorial Optimization, EGRES). - * - * Permission to use, modify and distribute this software is granted - * provided that this copyright notice appears in all copies. For - * precise terms see the accompanying LICENSE file. - * - * This software is provided "AS IS" with no warranty of any kind, - * express or implied, and with no claim as to its suitability for any - * purpose. - * - */ - -#ifndef LEMON_TEST_GRAPH_UTILS_TEST_H -#define LEMON_TEST_GRAPH_UTILS_TEST_H - - -#include "test_tools.h" -#include -#include - -//! \ingroup misc -//! \file -//! \brief Test cases for graph utils. -namespace lemon { - - template - void checkDigraphCounters() { - const int num = 5; - Digraph digraph; - addPetersen(digraph, num); - bidirDigraph(digraph); - check(countNodes(digraph) == 2*num, "Wrong node number."); - check(countArcs(digraph) == 6*num, "Wrong arc number."); - for (typename Digraph::NodeIt it(digraph); it != INVALID; ++it) { - check(countOutArcs(digraph, it) == 3, "Wrong out degree number."); - check(countInArcs(digraph, it) == 3, "Wrong in degree number."); - } - } - - template - void checkFindArc() { - typedef typename Digraph::Node Node; - typedef typename Digraph::Arc Arc; - typedef typename Digraph::NodeIt NodeIt; - typedef typename Digraph::ArcIt ArcIt; - Digraph digraph; - for (int i = 0; i < 10; ++i) { - digraph.addNode(); - } - DescriptorMap nodes(digraph); - typename DescriptorMap::InverseMap invNodes(nodes); - for (int i = 0; i < 100; ++i) { - int src = rnd[invNodes.size()]; - int trg = rnd[invNodes.size()]; - digraph.addArc(invNodes[src], invNodes[trg]); - } - typename Digraph::template ArcMap found(digraph, false); - DescriptorMap arcs(digraph); - for (NodeIt src(digraph); src != INVALID; ++src) { - for (NodeIt trg(digraph); trg != INVALID; ++trg) { - for (ConArcIt con(digraph, src, trg); con != INVALID; ++con) { - check(digraph.source(con) == src, "Wrong source."); - check(digraph.target(con) == trg, "Wrong target."); - check(found[con] == false, "The arc found already."); - found[con] = true; - } - } - } - for (ArcIt it(digraph); it != INVALID; ++it) { - check(found[it] == true, "The arc is not found."); - } - } - -} //namespace lemon - - -#endif diff -r 91fb4372688f -r 02f4d5d9bfd7 test/heap_test.cc --- a/test/heap_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/heap_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -42,7 +42,6 @@ using namespace lemon; using namespace lemon::concepts; - int main() { typedef int Item; @@ -77,7 +76,7 @@ run(); { - std::cerr << "Checking Bin Heap" << std::endl; + std::cout << "Checking Bin Heap" << std::endl; typedef BinHeap IntHeap; checkConcept, IntHeap>(); @@ -91,7 +90,7 @@ std::cout << timer << std::endl; } { - std::cerr << "Checking Fib Heap" << std::endl; + std::cout << "Checking Fib Heap" << std::endl; typedef FibHeap IntHeap; checkConcept, IntHeap>(); @@ -105,7 +104,7 @@ std::cout << timer << std::endl; } { - std::cerr << "Checking Radix Heap" << std::endl; + std::cout << "Checking Radix Heap" << std::endl; typedef RadixHeap IntHeap; checkConcept, IntHeap>(); @@ -120,7 +119,7 @@ } { - std::cerr << "Checking Bucket Heap" << std::endl; + std::cout << "Checking Bucket Heap" << std::endl; typedef BucketHeap IntHeap; checkConcept, IntHeap>(); @@ -134,7 +133,5 @@ std::cout << timer << std::endl; } - std::cout << __FILE__ ": All tests passed.\n"; - return 0; } diff -r 91fb4372688f -r 02f4d5d9bfd7 test/kruskal_test.cc --- a/test/kruskal_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/kruskal_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -28,7 +28,6 @@ #include #include - using namespace std; using namespace lemon; @@ -57,7 +56,6 @@ kruskal(g, r, ws.begin()); kruskal(ug, ur, uws.begin()); - } int main() { @@ -97,7 +95,7 @@ //Test with const map. check(kruskal(G, ConstMap(2), tree_map)==10, "Total cost should be 10"); - //Test with a edge map (filled with uniform costs). + //Test with an edge map (filled with uniform costs). check(kruskal(G, edge_cost_map, tree_map)==10, "Total cost should be 10"); diff -r 91fb4372688f -r 02f4d5d9bfd7 test/map_test.h --- a/test/map_test.h Sun Jun 15 22:03:33 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +0,0 @@ -/* -*- C++ -*- - * - * This file is a part of LEMON, a generic C++ optimization library - * - * Copyright (C) 2003-2008 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport - * (Egervary Research Group on Combinatorial Optimization, EGRES). - * - * Permission to use, modify and distribute this software is granted - * provided that this copyright notice appears in all copies. For - * precise terms see the accompanying LICENSE file. - * - * This software is provided "AS IS" with no warranty of any kind, - * express or implied, and with no claim as to its suitability for any - * purpose. - * - */ - -#ifndef LEMON_TEST_MAP_TEST_H -#define LEMON_TEST_MAP_TEST_H - - -#include -#include - -#include "test_tools.h" - - -//! \ingroup misc -//! \file -//! \brief Some utilities to test map classes. - -namespace lemon { - - - - template - void checkGraphNodeMap() { - Graph graph; - const int num = 16; - - typedef typename Graph::Node Node; - - std::vector nodes; - for (int i = 0; i < num; ++i) { - nodes.push_back(graph.addNode()); - } - typedef typename Graph::template NodeMap IntNodeMap; - IntNodeMap map(graph, 42); - for (int i = 0; i < int(nodes.size()); ++i) { - check(map[nodes[i]] == 42, "Wrong map constructor."); - } - for (int i = 0; i < num; ++i) { - nodes.push_back(graph.addNode()); - map[nodes.back()] = 23; - } - map = constMap(12); - for (int i = 0; i < int(nodes.size()); ++i) { - check(map[nodes[i]] == 12, "Wrong map constructor."); - } - graph.clear(); - nodes.clear(); - } - - template - void checkGraphArcMap() { - Graph graph; - const int num = 16; - - typedef typename Graph::Node Node; - typedef typename Graph::Arc Arc; - - std::vector nodes; - for (int i = 0; i < num; ++i) { - nodes.push_back(graph.addNode()); - } - - std::vector edges; - for (int i = 0; i < num; ++i) { - for (int j = 0; j < i; ++j) { - edges.push_back(graph.addArc(nodes[i], nodes[j])); - } - } - - typedef typename Graph::template ArcMap IntArcMap; - IntArcMap map(graph, 42); - - for (int i = 0; i < int(edges.size()); ++i) { - check(map[edges[i]] == 42, "Wrong map constructor."); - } - - for (int i = 0; i < num; ++i) { - for (int j = i + 1; j < num; ++j) { - edges.push_back(graph.addArc(nodes[i], nodes[j])); - map[edges.back()] = 23; - } - } - map = constMap(12); - for (int i = 0; i < int(edges.size()); ++i) { - check(map[edges[i]] == 12, "Wrong map constructor."); - } - graph.clear(); - edges.clear(); - } - - template - void checkGraphEdgeMap() { - Graph graph; - const int num = 16; - - typedef typename Graph::Node Node; - typedef typename Graph::Edge Edge; - - std::vector nodes; - for (int i = 0; i < num; ++i) { - nodes.push_back(graph.addNode()); - } - - std::vector edges; - for (int i = 0; i < num; ++i) { - for (int j = 0; j < i; ++j) { - edges.push_back(graph.addEdge(nodes[i], nodes[j])); - } - } - - typedef typename Graph::template EdgeMap IntEdgeMap; - IntEdgeMap map(graph, 42); - - for (int i = 0; i < int(edges.size()); ++i) { - check(map[edges[i]] == 42, "Wrong map constructor."); - } - - for (int i = 0; i < num; ++i) { - for (int j = i + 1; j < num; ++j) { - edges.push_back(graph.addEdge(nodes[i], nodes[j])); - map[edges.back()] = 23; - } - } - map = constMap(12); - for (int i = 0; i < int(edges.size()); ++i) { - check(map[edges[i]] == 12, "Wrong map constructor."); - } - graph.clear(); - edges.clear(); - } - -} - -#endif diff -r 91fb4372688f -r 02f4d5d9bfd7 test/random_test.cc --- a/test/random_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/random_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -19,11 +19,6 @@ #include #include "test_tools.h" -///\file \brief Test cases for random.h -/// -///\todo To be extended -/// - int seed_array[] = {1, 2}; int main() diff -r 91fb4372688f -r 02f4d5d9bfd7 test/test_tools.h --- a/test/test_tools.h Sun Jun 15 22:03:33 2008 +0200 +++ b/test/test_tools.h Sun Jun 15 22:05:23 2008 +0200 @@ -19,163 +19,29 @@ #ifndef LEMON_TEST_TEST_TOOLS_H #define LEMON_TEST_TEST_TOOLS_H +///\ingroup misc +///\file +///\brief Some utilities to write test programs. + #include -#include -#include -#include +///If \c rc is fail, writes an error message and exits. -#include -#include - -#include - -using namespace lemon; - -//! \ingroup misc -//! \file -//! \brief Some utilities to write test programs. - - -///If \c rc is fail, writes an error message end exit. - -///If \c rc is fail, writes an error message end exit. +///If \c rc is fail, writes an error message and exits. ///The error message contains the file name and the line number of the ///source code in a standard from, which makes it possible to go there ///using good source browsers like e.g. \c emacs. /// ///For example ///\code check(0==1,"This is obviously false.");\endcode will -///print this (and then exits). -///\verbatim digraph_test.cc:123: error: This is obviously false. \endverbatim +///print something like this (and then exits). +///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim /// -///\todo It should be in \c error.h +///\todo It should be in \c assert.h #define check(rc, msg) \ if(!(rc)) { \ std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \ abort(); \ } else { } \ -///Structure returned by \ref addPetersen(). - -///Structure returned by \ref addPetersen(). -/// -template struct PetStruct -{ - ///Vector containing the outer nodes. - std::vector outer; - ///Vector containing the inner nodes. - std::vector inner; - ///Vector containing the arcs of the inner circle. - std::vector incir; - ///Vector containing the arcs of the outer circle. - std::vector outcir; - ///Vector containing the chord arcs. - std::vector chords; -}; - - - -///Adds a Petersen digraph to \c G. - -///Adds a Petersen digraph to \c G. -///\return The nodes and arcs of the generated digraph. - -template -PetStruct addPetersen(Digraph &G,int num = 5) -{ - PetStruct n; - - for(int i=0;i void bidirDigraph(Digraph &G) -{ - typedef typename Digraph::Arc Arc; - typedef typename Digraph::ArcIt ArcIt; - - std::vector ee; - - for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e); - - for(typename std::vector::iterator p=ee.begin();p!=ee.end();p++) - G.addArc(G.target(*p),G.source(*p)); -} - - -/// \brief Checks the bidirectioned Petersen digraph. -/// -/// Checks the bidirectioned Petersen digraph. -/// -template void checkBidirPetersen(Digraph &G, int num = 5) -{ - typedef typename Digraph::Node Node; - - typedef typename Digraph::ArcIt ArcIt; - typedef typename Digraph::NodeIt NodeIt; - - checkDigraphNodeList(G, 2 * num); - checkDigraphArcList(G, 6 * num); - - for(NodeIt n(G);n!=INVALID;++n) { - checkDigraphInArcList(G, n, 3); - checkDigraphOutArcList(G, n, 3); - } -} - -///Structure returned by \ref addUPetersen(). - -///Structure returned by \ref addUPetersen(). -/// -template struct UPetStruct -{ - ///Vector containing the outer nodes. - std::vector outer; - ///Vector containing the inner nodes. - std::vector inner; - ///Vector containing the arcs of the inner circle. - std::vector incir; - ///Vector containing the arcs of the outer circle. - std::vector outcir; - ///Vector containing the chord arcs. - std::vector chords; -}; - -///Adds a Petersen digraph to the undirected \c G. - -///Adds a Petersen digraph to the undirected \c G. -///\return The nodes and arcs of the generated digraph. - -template -UPetStruct addUPetersen(Digraph &G,int num=5) -{ - UPetStruct n; - - for(int i=0;i -///\file \brief Test cases for time_measure.h -/// -///\todo To be extended - - using namespace lemon; void f() diff -r 91fb4372688f -r 02f4d5d9bfd7 test/unionfind_test.cc --- a/test/unionfind_test.cc Sun Jun 15 22:03:33 2008 +0200 +++ b/test/unionfind_test.cc Sun Jun 15 22:05:23 2008 +0200 @@ -16,8 +16,6 @@ * */ -#include - #include #include #include @@ -39,7 +37,7 @@ U.insert(n[1]); U.insert(n[2]); - check(U.join(n[1],n[2]) != -1,"Test failed."); + check(U.join(n[1],n[2]) != -1, "Something is wrong with UnionFindEnum"); U.insert(n[3]); U.insert(n[4]); @@ -48,54 +46,54 @@ U.insert(n[7]); - check(U.join(n[1],n[4]) != -1,"Test failed."); - check(U.join(n[2],n[4]) == -1,"Test failed."); - check(U.join(n[3],n[5]) != -1,"Test failed."); + check(U.join(n[1],n[4]) != -1, "Something is wrong with UnionFindEnum"); + check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum"); + check(U.join(n[3],n[5]) != -1, "Something is wrong with UnionFindEnum"); U.insert(n[8],U.find(n[5])); - check(U.size(U.find(n[4])) == 3,"Test failed."); - check(U.size(U.find(n[5])) == 3,"Test failed."); - check(U.size(U.find(n[6])) == 1,"Test failed."); - check(U.size(U.find(n[2])) == 3,"Test failed."); + check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); + check(U.size(U.find(n[5])) == 3, "Something is wrong with UnionFindEnum"); + check(U.size(U.find(n[6])) == 1, "Something is wrong with UnionFindEnum"); + check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum"); U.insert(n[9]); U.insert(n[10],U.find(n[9])); - check(U.join(n[8],n[10]) != -1,"Test failed."); + check(U.join(n[8],n[10]) != -1, "Something is wrong with UnionFindEnum"); - check(U.size(U.find(n[4])) == 3,"Test failed."); - check(U.size(U.find(n[9])) == 5,"Test failed."); + check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); + check(U.size(U.find(n[9])) == 5, "Something is wrong with UnionFindEnum"); - check(U.size(U.find(n[8])) == 5,"Test failed."); + check(U.size(U.find(n[8])) == 5, "Something is wrong with UnionFindEnum"); U.erase(n[9]); U.erase(n[1]); - check(U.size(U.find(n[10])) == 4,"Test failed."); - check(U.size(U.find(n[2])) == 2,"Test failed."); + check(U.size(U.find(n[10])) == 4, "Something is wrong with UnionFindEnum"); + check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum"); U.erase(n[6]); U.split(U.find(n[8])); - check(U.size(U.find(n[4])) == 2,"Test failed."); - check(U.size(U.find(n[3])) == 1,"Test failed."); - check(U.size(U.find(n[2])) == 2,"Test failed."); + check(U.size(U.find(n[4])) == 2, "Something is wrong with UnionFindEnum"); + check(U.size(U.find(n[3])) == 1, "Something is wrong with UnionFindEnum"); + check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum"); - check(U.join(n[3],n[4]) != -1,"Test failed."); - check(U.join(n[2],n[4]) == -1,"Test failed."); + check(U.join(n[3],n[4]) != -1, "Something is wrong with UnionFindEnum"); + check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum"); - check(U.size(U.find(n[4])) == 3,"Test failed."); - check(U.size(U.find(n[3])) == 3,"Test failed."); - check(U.size(U.find(n[2])) == 3,"Test failed."); + check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); + check(U.size(U.find(n[3])) == 3, "Something is wrong with UnionFindEnum"); + check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum"); U.eraseClass(U.find(n[4])); U.eraseClass(U.find(n[7]));