# HG changeset patch # User deba # Date 1121699422 0 # Node ID f694f75de683503e83758ffa4dd0521526a692a2 # Parent 3ea28f39218b3783544268900ce4e4bed5aab76c Improving tests. diff -r 3ea28f39218b -r f694f75de683 test/graph_utils_test.cc --- a/test/graph_utils_test.cc Mon Jul 18 15:09:37 2005 +0000 +++ b/test/graph_utils_test.cc Mon Jul 18 15:10:22 2005 +0000 @@ -50,15 +50,26 @@ ///\file { // checking list graph checkGraphCounters(); + checkFindEdge(); } { // checking smart graph checkGraphCounters(); + checkFindEdge(); } { int num = 5; FullGraph fg(num); check(countNodes(fg) == num, "FullGraph: wrong node number."); - check(countEdges(fg) == num*num, "FullGraph: wrong edge number."); + check(countEdges(fg) == num*num, "FullGraph: wrong edge number."); + for (FullGraph::NodeIt src(fg); src != INVALID; ++src) { + for (FullGraph::NodeIt trg(fg); trg != INVALID; ++trg) { + ConEdgeIt con(fg, src, trg); + check(con != INVALID, "There is no connecting edge."); + check(fg.source(con) == src, "Wrong source."); + check(fg.target(con) == trg, "Wrong target."); + check(++con == INVALID, "There is more connecting edge."); + } + } } //check In/OutDegMap (and SnapShot feature) diff -r 3ea28f39218b -r f694f75de683 test/graph_utils_test.h --- a/test/graph_utils_test.h Mon Jul 18 15:09:37 2005 +0000 +++ b/test/graph_utils_test.h Mon Jul 18 15:10:22 2005 +0000 @@ -18,6 +18,8 @@ #include "test_tools.h" +#include +#include //! \ingroup misc //! \file @@ -37,6 +39,41 @@ check(countInEdges(graph, it) == 3, "Wrong in degree number."); } } + + template + void checkFindEdge() { + typedef typename Graph::Node Node; + typedef typename Graph::Edge Edge; + typedef typename Graph::NodeIt NodeIt; + typedef typename Graph::EdgeIt EdgeIt; + Graph graph; + srand(time(0)); + 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 = (int)(rand() / (RAND_MAX + 1.0) * invNodes.size()); + int trg = (int)(rand() / (RAND_MAX + 1.0) * invNodes.size()); + graph.addEdge(invNodes[src], invNodes[trg]); + } + typename Graph::template EdgeMap found(graph, false); + 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.source(con) == src, "Wrong source."); + check(graph.target(con) == trg, "Wrong target."); + check(found[con] == false, "The edge found already."); + found[con] = true; + } + } + } + for (EdgeIt it(graph); it != INVALID; ++it) { + check(found[it] == true, "The edge is not found."); + } + } } //namespace lemon diff -r 3ea28f39218b -r f694f75de683 test/undir_graph_test.cc --- a/test/undir_graph_test.cc Mon Jul 18 15:09:37 2005 +0000 +++ b/test/undir_graph_test.cc Mon Jul 18 15:10:22 2005 +0000 @@ -40,6 +40,8 @@ checkConcept(); checkConcept(); + checkConcept(); + checkConcept(); } @@ -116,5 +118,10 @@ check_graph(); check_graph(); + { + UndirFullGraph g(5); + check_item_counts(g, 5, 10); + } + return 0; }