|
Boost-Commit : |
From: asutton_at_[hidden]
Date: 2008-06-16 09:18:21
Author: asutton
Date: 2008-06-16 09:18:20 EDT (Mon, 16 Jun 2008)
New Revision: 46421
URL: http://svn.boost.org/trac/boost/changeset/46421
Log:
Added a simple demangler template.
Started rewriting the tests in a slightly more organized manner.
Text files modified:
sandbox/SOC/2008/graphs/branches/iu/libs/graphs/demangle.hpp | 10 ++
sandbox/SOC/2008/graphs/branches/iu/libs/graphs/un.cpp | 122 +++++++++++----------------------------
2 files changed, 45 insertions(+), 87 deletions(-)
Modified: sandbox/SOC/2008/graphs/branches/iu/libs/graphs/demangle.hpp
==============================================================================
--- sandbox/SOC/2008/graphs/branches/iu/libs/graphs/demangle.hpp (original)
+++ sandbox/SOC/2008/graphs/branches/iu/libs/graphs/demangle.hpp 2008-06-16 09:18:20 EDT (Mon, 16 Jun 2008)
@@ -6,9 +6,17 @@
#include <typeinfo>
#include <cxxabi.h>
-std::string demangle(std::string const& name)
+inline std::string
+demangle(std::string const& name)
{
return std::string(abi::__cxa_demangle(name.c_str(), 0, 0, 0));
}
+template <typename T>
+inline std::string
+demangle()
+{
+ return demangle(typeid(T).name());
+}
+
#endif
Modified: sandbox/SOC/2008/graphs/branches/iu/libs/graphs/un.cpp
==============================================================================
--- sandbox/SOC/2008/graphs/branches/iu/libs/graphs/un.cpp (original)
+++ sandbox/SOC/2008/graphs/branches/iu/libs/graphs/un.cpp 2008-06-16 09:18:20 EDT (Mon, 16 Jun 2008)
@@ -2,6 +2,7 @@
#include <iostream>
#include <set>
+#include <boost/assert.hpp>
#include <boost/utility.hpp>
#include <boost/graphs/undirected_graph.hpp>
@@ -29,96 +30,52 @@
}
template <typename Graph>
-void add_verts(Graph& g)
+void test_add_vertices()
{
- cout << "*** Add Vertices" << endl;
- cout << "*** " << demangle(typeid(Graph).name()) << endl;
+ Graph g;
+ list<typename Graph::vertex_descriptor> V;
for(int i = 0; i < 5; ++i) {
- g.add_vertex(i);
+ V.push_back(g.add_vertex(i));
}
}
template <typename Graph>
-void del_verts(Graph& g)
-{
- // Just remove the first two vertices
- typename Graph::vertex_descriptor u = *g.begin_vertices();
- typename Graph::vertex_descriptor v = *next(g.begin_vertices());
- g.remove_vertex(u);
- g.remove_vertex(v);
-}
-
-template <typename Graph>
-void add_edges(Graph& g)
-{
- cout << "*** Add Edges" << endl;
- cout << "*** " << demangle(typeid(Graph).name()) << endl;
- typename Graph::vertex_descriptor u = g.add_vertex(100);
- typename Graph::vertex_descriptor v = g.add_vertex(101);
- typename Graph::vertex_descriptor w = g.add_vertex(102);
- g.add_edge(v, u);
- g.add_edge(w, u);
-}
-
-template <typename Graph>
-void add_and_del_edges(Graph& g)
-{
- cout << "*** Add/Delete Edges" << endl;
- cout << "*** " << demangle(typeid(Graph).name()) << endl;
- typename Graph::vertex_descriptor u = g.add_vertex(100);
- typename Graph::vertex_descriptor v = g.add_vertex(101);
- typename Graph::vertex_descriptor w = g.add_vertex(102);
- typename Graph::edge_descriptor e1 = g.add_edge(v, u);
- typename Graph::edge_descriptor e2 = g.add_edge(w, u);
-
- g.remove_edge(e1);
- g.remove_edge(e2);
-}
-
-template <typename Graph>
-void test_multi_edge(Graph& g)
+void test_add_remove_vertices()
{
- cout << "*** Add/Delete Multi-Edges" << endl;
- cout << "*** " << demangle(typeid(Graph).name()) << endl;
- typename Graph::vertex_descriptor u = g.add_vertex(200);
- typename Graph::vertex_descriptor v = g.add_vertex(201);
- g.add_edge(u, v);
- g.add_edge(v, u);
- g.add_edge(u, v);
- g.add_edge(v, u);
- g.remove_edges(u, v);
-}
-
-template <typename Graph>
-void test_remove_vert(Graph& g)
-{
- cout << "*** Remove Vertex" << endl;
- cout << "*** " << demangle(typeid(Graph).name()) << endl;
- typename Graph::vertex_descriptor u = g.add_vertex(300);
- typename Graph::vertex_descriptor v = g.add_vertex(301);
- typename Graph::vertex_descriptor w = g.add_vertex(302);
- g.add_edge(u, v, 1);
- g.add_edge(v, w, 2);
- g.remove_vertex(v);
+ Graph g;
+ list<typename Graph::vertex_descriptor> V;
+ for(int i = 0; i < 5; ++i) {
+ V.push_back(g.add_vertex(i));
+ }
+ BOOST_ASSERT(g.num_vertices() == 5);
+ while(!V.empty()) {
+ g.remove_vertex(V.front());
+ V.pop_front();
+ }
+ BOOST_ASSERT(g.num_vertices() == 0);
}
template <typename Graph>
-void print_verts(Graph& g)
+void test_make_simple_triangle()
{
- typename Graph::vertex_range rng = g.vertices();
- for( ; rng.first != rng.second; ++rng.first) {
- typename Graph::vertex_descriptor v = *rng.first;
- cout << "vert: " << g[v] << " w/degree == " << g.degree(v) << endl;
+ Graph g;
+ vector<typename Graph::vertex_descriptor> V;
+ for(int i = 0; i < 3; ++i) {
+ V.push_back(g.add_vertex(i));
}
+ g.add_edge(V[0], V[1]);
+ g.add_edge(V[1], V[2]);
+ g.add_edge(V[2], V[0]);
+ BOOST_ASSERT(g.num_vertices() == 3);
+ BOOST_ASSERT(g.num_edges() == 3);
}
+
int main()
{
- // vec_vec();
- // cout << endl << endl;
+ vec_vec();
list_list();
- // cout << endl << endl;
- // set_set();
+ set_set();
return 0;
}
@@ -126,10 +83,8 @@
void vec_vec()
{
typedef undirected_graph<City, Road, vertex_vector, edge_vector> Graph;
-
- Graph g;
- add_verts(g);
- add_edges(g);
+ test_add_vertices<Graph>();
+ test_make_simple_triangle<Graph>();
}
void list_list()
@@ -137,20 +92,15 @@
typedef undirected_graph<City, Road, vertex_list, edge_list> Graph;
Graph g;
- // add_verts(g);
- // add_and_del_edges(g);
- // test_multi_edge(g);
- test_remove_vert(g);
+ test_add_remove_vertices<Graph>();
+ test_make_simple_triangle<Graph>();
}
void set_set()
{
typedef undirected_graph<City, Road, vertex_set<>, edge_set<> > Graph;
-
- Graph g;
- add_verts(g);
- add_and_del_edges(g);
- test_multi_edge(g);
+ test_add_remove_vertices<Graph>();
+ test_make_simple_triangle<Graph>();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk