[Lemon-commits] [lemon_svn] deba: r1315 - hugo/branches/graph_factory/src/test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:44:34 CET 2006
Author: deba
Date: Wed Oct 27 13:03:49 2004
New Revision: 1315
Added:
hugo/branches/graph_factory/src/test/graph_utils_test.cc
hugo/branches/graph_factory/src/test/graph_utils_test.h
Modified:
hugo/branches/graph_factory/src/test/Makefile.am
hugo/branches/graph_factory/src/test/graph_test.cc
hugo/branches/graph_factory/src/test/graph_test.h
hugo/branches/graph_factory/src/test/map_test.h
hugo/branches/graph_factory/src/test/test_tools.h
Log:
New test file for test graph utils.
Test for item counters.
Some change in the test functions placement.
Modified: hugo/branches/graph_factory/src/test/Makefile.am
==============================================================================
--- hugo/branches/graph_factory/src/test/Makefile.am (original)
+++ hugo/branches/graph_factory/src/test/Makefile.am Wed Oct 27 13:03:49 2004
@@ -2,13 +2,19 @@
EXTRA_DIST = preflow_graph.dim #input file for preflow_test.cc
-noinst_HEADERS = test_tools.h graph_test.h sym_graph_test.h
+noinst_HEADERS = \
+ test_tools.h \
+ graph_test.h \
+ sym_graph_test.h \
+ map_test.h \
+ grap_utils_test.h
check_PROGRAMS = \
bfs_test \
dfs_test \
dijkstra_test \
graph_test \
+ graph_utils_test \
kruskal_test \
min_cost_flow_test \
new_graph_test \
@@ -28,6 +34,7 @@
dfs_test_SOURCES = dfs_test.cc
dijkstra_test_SOURCES = dijkstra_test.cc
graph_test_SOURCES = graph_test.cc
+graph_utils_test_SOURCES = graph_utils_test.cc
kruskal_test_SOURCES = kruskal_test.cc
min_cost_flow_test_SOURCES = min_cost_flow_test.cc
new_graph_test_SOURCES = new_graph_test.cc
Modified: hugo/branches/graph_factory/src/test/graph_test.cc
==============================================================================
--- hugo/branches/graph_factory/src/test/graph_test.cc (original)
+++ hugo/branches/graph_factory/src/test/graph_test.cc Wed Oct 27 13:03:49 2004
@@ -17,39 +17,6 @@
using namespace lemon::skeleton;
-
-template<class Graph> void bidirPetersen(Graph &G)
-{
- typedef typename Graph::Edge Edge;
- typedef typename Graph::EdgeIt EdgeIt;
-
- checkGraphEdgeList(G,15);
-
- std::vector<Edge> ee;
-
- for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
-
- for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
- G.addEdge(G.head(*p),G.tail(*p));
-}
-
-template<class Graph> void checkPetersen(Graph &G)
-{
- typedef typename Graph::Node Node;
-
- typedef typename Graph::EdgeIt EdgeIt;
- typedef typename Graph::NodeIt NodeIt;
-
- checkGraphNodeList(G,10);
- checkGraphEdgeList(G,30);
-
- for(NodeIt n(G);n!=INVALID;++n) {
- checkGraphInEdgeList(G,n,3);
- checkGraphOutEdgeList(G,n,3);
- }
-}
-
-
int main() {
///\file
{ // checking graph components
@@ -81,20 +48,16 @@
{ // checking list graph
function_requires<ErasableGraphConcept<ListGraph> >();
- ListGraph G;
- addPetersen(G);
- bidirPetersen(G);
- checkPetersen(G);
+ checkGraph<ListGraph>();
checkGraphNodeMap<ListGraph>();
+ checkGraphEdgeMap<ListGraph>();
}
{ // checking smart graph
function_requires<ExtendableGraphConcept<SmartGraph> >();
- SmartGraph G;
- addPetersen(G);
- bidirPetersen(G);
- checkPetersen(G);
+ checkGraph<SmartGraph>();
checkGraphNodeMap<SmartGraph>();
+ checkGraphEdgeMap<SmartGraph>();
}
{ // checking full graph
function_requires<StaticGraphConcept<FullGraph> >();
Modified: hugo/branches/graph_factory/src/test/graph_test.h
==============================================================================
--- hugo/branches/graph_factory/src/test/graph_test.h (original)
+++ hugo/branches/graph_factory/src/test/graph_test.h Wed Oct 27 13:03:49 2004
@@ -21,7 +21,7 @@
//! \ingroup misc
//! \file
-//! \brief Some utility to test graph classes.
+//! \brief Some utility and test cases to test graph classes.
namespace lemon {
template<class Graph> void checkGraphNodeList(Graph &G, int nn)
@@ -71,6 +71,15 @@
check(e==INVALID,"Wrong InEdge list linking.");
}
+ template <class Graph>
+ void checkGraph() {
+ const int num = 5;
+ Graph G;
+ addPetersen(G, num);
+ bidirGraph(G);
+ checkBidirPetersen(G, num);
+ }
+
///\file
///\todo Check head(), tail() as well;
Added: hugo/branches/graph_factory/src/test/graph_utils_test.cc
==============================================================================
--- (empty file)
+++ hugo/branches/graph_factory/src/test/graph_utils_test.cc Wed Oct 27 13:03:49 2004
@@ -0,0 +1,29 @@
+// -*- c++ -*-
+
+#include <iostream>
+#include <vector>
+
+#include <lemon/list_graph.h>
+#include <lemon/smart_graph.h>
+#include <lemon/full_graph.h>
+
+#include "test_tools.h"
+#include "graph_utils_test.h"
+
+
+using namespace lemon;
+
+
+int main() {
+ ///\file
+ { // checking list graph
+ checkGraphCounters<ListGraph>();
+ }
+ { // checking smart graph
+ checkGraphCounters<SmartGraph>();
+ }
+
+ std::cout << __FILE__ ": All tests passed.\n";
+
+ return 0;
+}
Added: hugo/branches/graph_factory/src/test/graph_utils_test.h
==============================================================================
--- (empty file)
+++ hugo/branches/graph_factory/src/test/graph_utils_test.h Wed Oct 27 13:03:49 2004
@@ -0,0 +1,44 @@
+/* -*- C++ -*-
+ * src/test/graph_utils_test.h - Part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Combinatorial Optimization Research Group, 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"
+
+//! \ingroup misc
+//! \file
+//! \brief Test cases for graph utils.
+namespace lemon {
+
+ template <typename Graph>
+ void checkGraphCounters() {
+ const int num = 5;
+ Graph graph;
+ addPetersen(graph, num);
+ bidirGraph(graph);
+ check(countNodes(graph) == 2*num, "Wrong node counter.");
+ check(countEdges(graph) == 6*num, "Wrong edge counter.");
+ for (typename Graph::NodeIt it(graph); it != INVALID; ++it) {
+ check(countOutEdges(graph, it) == 3, "Wrong out degree counter.");
+ check(countInEdges(graph, it) == 3, "Wrong in degree counter.");
+ }
+ }
+
+} //namespace lemon
+
+
+#endif
Modified: hugo/branches/graph_factory/src/test/map_test.h
==============================================================================
--- hugo/branches/graph_factory/src/test/map_test.h (original)
+++ hugo/branches/graph_factory/src/test/map_test.h Wed Oct 27 13:03:49 2004
@@ -60,24 +60,28 @@
typedef typename Graph::Node Node;
typedef typename Graph::Edge Edge;
-
+
std::vector<Node> nodes;
for (int i = 0; i < num; ++i) {
- nodes.push_back();
+ nodes.push_back(graph.addNode());
}
+
std::vector<Edge> edges;
for (int i = 0; i < num; ++i) {
- for (int j = 0; j < i; ++i) {
+ for (int j = 0; j < i; ++j) {
edges.push_back(graph.addEdge(nodes[i], nodes[j]));
}
}
+
typedef typename Graph::template EdgeMap<int> 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; ++i) {
+ for (int j = i + 1; j < num; ++j) {
edges.push_back(graph.addEdge(nodes[i], nodes[j]));
map[edges.back()] = 23;
}
Modified: hugo/branches/graph_factory/src/test/test_tools.h
==============================================================================
--- hugo/branches/graph_factory/src/test/test_tools.h (original)
+++ hugo/branches/graph_factory/src/test/test_tools.h Wed Oct 27 13:03:49 2004
@@ -70,7 +70,7 @@
///\return The nodes and edges of the generated graph.
template<typename Graph>
-PetStruct<Graph> addPetersen(Graph &G,int num=5)
+PetStruct<Graph> addPetersen(Graph &G,int num = 5)
{
PetStruct<Graph> n;
@@ -81,12 +81,50 @@
for(int i=0;i<num;i++) {
n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
- n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
- n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
+ n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1) % num]));
+ n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2) % num]));
}
return n;
}
+/// \brief Adds to the graph the reverse pair of all edge.
+///
+/// Adds to the graph the reverse pair of all edge.
+///
+template<class Graph> void bidirGraph(Graph &G)
+{
+ typedef typename Graph::Edge Edge;
+ typedef typename Graph::EdgeIt EdgeIt;
+
+ std::vector<Edge> ee;
+
+ for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
+
+ for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
+ G.addEdge(G.head(*p),G.tail(*p));
+}
+
+
+/// \brief Checks the bidirectioned Petersen graph.
+///
+/// Checks the bidirectioned Petersen graph.
+///
+template<class Graph> void checkBidirPetersen(Graph &G, int num = 5)
+{
+ typedef typename Graph::Node Node;
+
+ typedef typename Graph::EdgeIt EdgeIt;
+ typedef typename Graph::NodeIt NodeIt;
+
+ checkGraphNodeList(G, 2 * num);
+ checkGraphEdgeList(G, 6 * num);
+
+ for(NodeIt n(G);n!=INVALID;++n) {
+ checkGraphInEdgeList(G, n, 3);
+ checkGraphOutEdgeList(G, n, 3);
+ }
+}
+
///Structure returned by \ref addSymPetersen().
///Structure returned by \ref addSymPetersen().
More information about the Lemon-commits
mailing list