Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53135 - trunk/libs/graph/test
From: asutton_at_[hidden]
Date: 2009-05-20 12:54:49


Author: asutton
Date: 2009-05-20 12:54:46 EDT (Wed, 20 May 2009)
New Revision: 53135
URL: http://svn.boost.org/trac/boost/changeset/53135

Log:
Added concept checks to the interface testing harness.

Text files modified:
   trunk/libs/graph/test/test_construction.hpp | 36 ++++++++++++++++++++++++--------
   trunk/libs/graph/test/test_destruction.hpp | 42 +++++++++++++++++++++++++-----------
   trunk/libs/graph/test/test_direction.hpp | 45 ++++++++++++++++++++++++----------------
   trunk/libs/graph/test/test_graph.hpp | 20 ++++++++++-------
   trunk/libs/graph/test/test_graphs.cpp | 3 -
   trunk/libs/graph/test/test_iteration.hpp | 12 ++++++++--
   trunk/libs/graph/test/test_properties.hpp | 31 ++++++++++++++++++++-------
   7 files changed, 128 insertions(+), 61 deletions(-)

Modified: trunk/libs/graph/test/test_construction.hpp
==============================================================================
--- trunk/libs/graph/test/test_construction.hpp (original)
+++ trunk/libs/graph/test/test_construction.hpp 2009-05-20 12:54:46 EDT (Wed, 20 May 2009)
@@ -24,20 +24,30 @@
 // This matches MutableGraph, so just add some vertices.
 template <typename Graph>
 void build_graph(Graph& g, boost::mpl::true_, boost::mpl::false_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((VertexListGraphConcept<Graph>));
+ BOOST_CONCEPT_ASSERT((VertexMutableGraphConcept<Graph>));
+
     std::cout << "...build_normal\n";
     for(std::size_t i = 0; i < N; ++i) {
- boost::add_vertex(g);
+ add_vertex(g);
     }
+ BOOST_ASSERT(num_vertices(g) == N);
 }
 
 // This will match labeled graphs.
 template <typename Graph>
 void build_graph(Graph& g, boost::mpl::false_, boost::mpl::true_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((VertexListGraphConcept<Graph>));
+ // BOOST_CONCEPT_ASSERT((VertexMutableGraphConcept<Graph>));
+
     std::cout << "...build_labeled\n";
     // Add each vertex labeled with the number i.
     for(std::size_t i = 0; i < N; ++i) {
- boost::add_vertex(i, g);
+ add_vertex(i, g);
     }
+ BOOST_ASSERT(num_vertices(g) == N);
 }
 //@}
 
@@ -52,20 +62,28 @@
 //@{
 template <typename Graph, typename VertexSet>
 void connect_graph(Graph& g, VertexSet const& verts, boost::mpl::false_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept<Graph>));
+ BOOST_CONCEPT_ASSERT((EdgeMutableGraphConcept<Graph>));
+
     std::cout << "...connect_normal\n";
     Pair *f, *l;
- for(boost::tie(f, l) = edge_pairs(); f != l; ++f) {
+ for(tie(f, l) = edge_pairs(); f != l; ++f) {
         Pair const& e = *f;
- boost::add_edge(verts[e.first], verts[e.second], g);
+ add_edge(verts[e.first], verts[e.second], g);
     }
 
     // Is the lollipop connected? Is the lollipop not connected to the roof?
- BOOST_ASSERT(boost::edge(verts[5], verts[3], g).second == true);
- BOOST_ASSERT(boost::edge(verts[5], verts[0], g).second == false);
+ BOOST_ASSERT(edge(verts[5], verts[3], g).second == true);
+ BOOST_ASSERT(edge(verts[5], verts[0], g).second == false);
 }
 
 template <typename Graph, typename VertexSet>
 void connect_graph(Graph& g, VertexSet const& verts, boost::mpl::true_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept<Graph>));
+ // BOOST_CONCEPT_ASSERT((EdgeMutableGraphConcept<Graph>));
+
     std::cout << "...connect_labeled\n";
     // With labeled graphs, we want to operate directly on the edge numbers
     // rather than looking up the correct vertex index. This is because the
@@ -73,12 +91,12 @@
     Pair* p = edge_pairs().first;
     for(std::size_t i = 0; i < M; ++i) {
         Pair const& e = p[i];
- boost::add_edge_by_label(e.first, e.second, g);
+ add_edge_by_label(e.first, e.second, g);
     }
 
     // Is the lollipop connected?
- BOOST_ASSERT(boost::edge_by_label(5, 3, g).second == true);
- BOOST_ASSERT(boost::edge_by_label(5, 0, g).second == false);
+ BOOST_ASSERT(edge_by_label(5, 3, g).second == true);
+ BOOST_ASSERT(edge_by_label(5, 0, g).second == false);
 }
 //@}
 

Modified: trunk/libs/graph/test/test_destruction.hpp
==============================================================================
--- trunk/libs/graph/test/test_destruction.hpp (original)
+++ trunk/libs/graph/test/test_destruction.hpp 2009-05-20 12:54:46 EDT (Wed, 20 May 2009)
@@ -21,19 +21,27 @@
 // This matches MutableGraph, so just remove a vertex and then clear.
 template <typename Graph, typename VertexSet>
 void destroy_graph(Graph& g, VertexSet const& verts, boost::mpl::true_, boost::mpl::false_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((VertexListGraphConcept<Graph>));
+ BOOST_CONCEPT_ASSERT((VertexMutableGraphConcept<Graph>));
+
     std::cout << "...destroy_normal\n";
     // Remove the roof vertex
- boost::remove_vertex(verts[0], g);
- BOOST_ASSERT(boost::num_vertices(g) == N - 1);
+ remove_vertex(verts[0], g);
+ BOOST_ASSERT(num_vertices(g) == N - 1);
 }
 
 // This will match labeled graphs.
 template <typename Graph, typename VertexSet>
 void destroy_graph(Graph& g, VertexSet const& verts, boost::mpl::false_, boost::mpl::true_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((VertexListGraphConcept<Graph>));
+ // function_requires< VeretexMutableGraphConcept<Graph> >();
+
     std::cout << "...destroy_labeled\n";
     // Remove the roof vertex
- boost::remove_vertex(0, g);
- BOOST_ASSERT(boost::num_vertices(g) == N - 1);
+ remove_vertex(0, g);
+ BOOST_ASSERT(num_vertices(g) == N - 1);
 }
 //@}
 
@@ -50,29 +58,37 @@
 
 template <typename Graph, typename VertexSet>
 void disconnect_graph(Graph& g, VertexSet const& verts, boost::mpl::false_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((EdgeListGraphConcept<Graph>));
+ BOOST_CONCEPT_ASSERT((EdgeMutableGraphConcept<Graph>));
+
     std::cout << "...disconnect_normal\n";
- typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
+ typedef typename graph_traits<Graph>::edge_descriptor Edge;
 
     // Disconnect the "lollipop" from the house.
- Edge e = boost::edge(verts[5], verts[3], g).first;
- boost::remove_edge(e, g);
- BOOST_ASSERT(boost::num_edges(g) == M - 1);
+ Edge e = edge(verts[5], verts[3], g).first;
+ remove_edge(e, g);
+ BOOST_ASSERT(num_edges(g) == M - 1);
 
     // Remove the "floor" edge from the house.
- boost::remove_edge(verts[3], verts[2], g);
- BOOST_ASSERT(boost::num_edges(g) == M - 2);
+ remove_edge(verts[3], verts[2], g);
+ BOOST_ASSERT(num_edges(g) == M - 2);
 
     // Fully disconnect the roof vertex.
     clear_vertex(verts[0], g);
- BOOST_ASSERT(boost::num_edges(g) == M - 4);
+ BOOST_ASSERT(num_edges(g) == M - 4);
 
     // What happens if we try to remove an edge that doesn't exist?
- boost::remove_edge(verts[5], verts[0], g);
- BOOST_ASSERT(boost::num_edges(g) == M - 4);
+ remove_edge(verts[5], verts[0], g);
+ BOOST_ASSERT(num_edges(g) == M - 4);
 }
 
 template <typename Graph, typename VertexSet>
 void disconnect_graph(Graph& g, VertexSet const& verts, boost::mpl::true_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((EdgeListGraphConcept<Graph>));
+ // BOOST_CONCEPT_ASSERT((EdgeMutableGraphConcept<Graph>));
+
     std::cout << "...disconnect_labeled\n";
     typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
 

Modified: trunk/libs/graph/test/test_direction.hpp
==============================================================================
--- trunk/libs/graph/test/test_direction.hpp (original)
+++ trunk/libs/graph/test/test_direction.hpp 2009-05-20 12:54:46 EDT (Wed, 20 May 2009)
@@ -16,23 +16,26 @@
 //@{
 template <typename Graph, typename VertexSet>
 void test_outdirected_graph(Graph const& g, VertexSet const& verts, boost::mpl::true_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((IncidenceGraphConcept<Graph>));
+
     std::cout << "...test_outdirected_graph\n";
- typedef typename boost::graph_traits<Graph>::out_edge_iterator OutIter;
+ typedef typename graph_traits<Graph>::out_edge_iterator OutIter;
     typedef std::pair<OutIter, OutIter> OutRange;
     typedef std::vector<OutRange> OutSet;
 
     // Collect all of the out edge ranges from the graph.
     OutSet outs(verts.size());
     for(size_t i = 0; i < verts.size(); ++i) {
- outs[i] = boost::out_edges(verts[i], g);
+ outs[i] = out_edges(verts[i], g);
     }
 
- BOOST_ASSERT(boost::distance(outs[0]) == 0);
- BOOST_ASSERT(boost::distance(outs[1]) == 1);
- BOOST_ASSERT(boost::distance(outs[2]) == 1);
- BOOST_ASSERT(boost::distance(outs[3]) == 2);
- BOOST_ASSERT(boost::distance(outs[4]) == 2);
- BOOST_ASSERT(boost::distance(outs[5]) == 1);
+ BOOST_ASSERT(distance(outs[0]) == 0);
+ BOOST_ASSERT(distance(outs[1]) == 1);
+ BOOST_ASSERT(distance(outs[2]) == 1);
+ BOOST_ASSERT(distance(outs[3]) == 2);
+ BOOST_ASSERT(distance(outs[4]) == 2);
+ BOOST_ASSERT(distance(outs[5]) == 1);
 
     // Verify that the edges are actually correct.
     // TODO: Find a better way of testing connectivity with multiple edges.
@@ -56,15 +59,18 @@
 //@{
 template <typename Graph, typename VertexSet>
 void test_indirected_graph(Graph const& g, VertexSet const& verts, boost::mpl::true_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept<Graph>));
+
     std::cout << "...test_indirected_graph\n";
- typedef typename boost::graph_traits<Graph>::in_edge_iterator InIter;
+ typedef typename graph_traits<Graph>::in_edge_iterator InIter;
     typedef std::pair<InIter, InIter> InRange;
     typedef std::vector<InRange> InSet;
 
     // Collect all of the in edges from the graph.
     InSet ins(verts.size());
     for(size_t i = 0; i < verts.size(); ++i) {
- ins[i] = boost::in_edges(verts[i], g);
+ ins[i] = in_edges(verts[i], g);
     }
 
     BOOST_ASSERT(distance(ins[0]) == 2);
@@ -91,25 +97,28 @@
  */
 template <typename Graph, typename VertexSet>
 void test_undirected_graph(Graph const& g, VertexSet const& verts, boost::mpl::true_) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((IncidenceGraphConcept<Graph>));
+
     std::cout << "...test_undirected_graph\n";
- typedef typename boost::graph_traits<Graph>::out_edge_iterator OutIter;
+ typedef typename graph_traits<Graph>::out_edge_iterator OutIter;
     typedef std::pair<OutIter, OutIter> OutRange;
     typedef std::vector<OutRange> OutSet;
 
     // The set of out edges is the same as the set of incident edges.
     OutSet outs(verts.size());
     for(size_t i = 0; i < verts.size(); ++i) {
- outs[i] = boost::out_edges(verts[i], g);
+ outs[i] = out_edges(verts[i], g);
     }
 
     // TODO: Actually test the end connections to ensure that these are
     // definitely correct.
- BOOST_ASSERT(boost::distance(outs[0]) == 2);
- BOOST_ASSERT(boost::distance(outs[1]) == 3);
- BOOST_ASSERT(boost::distance(outs[2]) == 2);
- BOOST_ASSERT(boost::distance(outs[3]) == 3);
- BOOST_ASSERT(boost::distance(outs[4]) == 3);
- BOOST_ASSERT(boost::distance(outs[5]) == 1);
+ BOOST_ASSERT(distance(outs[0]) == 2);
+ BOOST_ASSERT(distance(outs[1]) == 3);
+ BOOST_ASSERT(distance(outs[2]) == 2);
+ BOOST_ASSERT(distance(outs[3]) == 3);
+ BOOST_ASSERT(distance(outs[4]) == 3);
+ BOOST_ASSERT(distance(outs[5]) == 1);
 }
 
 template <typename Graph, typename VertexSet>

Modified: trunk/libs/graph/test/test_graph.hpp
==============================================================================
--- trunk/libs/graph/test/test_graph.hpp (original)
+++ trunk/libs/graph/test/test_graph.hpp 2009-05-20 12:54:46 EDT (Wed, 20 May 2009)
@@ -20,6 +20,7 @@
 #include <boost/assert.hpp>
 #include <boost/graph/graph_traits.hpp>
 #include <boost/graph/graph_mutability_traits.hpp>
+#include <boost/graph/graph_concepts.hpp>
 
 #include "typestr.hpp"
 
@@ -87,23 +88,26 @@
 
 template <typename Graph>
 void test_graph(Graph& g) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((GraphConcept<Graph>));
+
     std::cout << typestr(g) << "\n";
 
     // Define a bunch of tags for the graph.
- typename boost::graph_has_add_vertex<Graph>::type can_add_vertex;
- typename boost::graph_has_remove_vertex<Graph>::type can_remove_vertex;
- typename boost::is_labeled_graph<Graph>::type is_labeled;
- typename boost::is_directed_unidirectional_graph<Graph>::type is_directed;
- typename boost::is_directed_bidirectional_graph<Graph>::type is_bidirectional;
- typename boost::is_undirected_graph<Graph>::type is_undirected;
+ typename graph_has_add_vertex<Graph>::type can_add_vertex;
+ typename graph_has_remove_vertex<Graph>::type can_remove_vertex;
+ typename is_labeled_graph<Graph>::type is_labeled;
+ typename is_directed_unidirectional_graph<Graph>::type is_directed;
+ typename is_directed_bidirectional_graph<Graph>::type is_bidirectional;
+ typename is_undirected_graph<Graph>::type is_undirected;
 
     // Test constrution and vertex list.
     build_graph(g, can_add_vertex, is_labeled);
     test_vertex_list_graph(g);
 
     // Collect the vertices for an easy method of "naming" them.
- typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
- typedef typename boost::graph_traits<Graph>::vertex_iterator VertexIterator;
+ typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
+ typedef typename graph_traits<Graph>::vertex_iterator VertexIterator;
     std::vector<Vertex> verts;
     std::pair<VertexIterator, VertexIterator> rng = vertices(g);
     for( ; rng.first != rng.second; ++rng.first) {

Modified: trunk/libs/graph/test/test_graphs.cpp
==============================================================================
--- trunk/libs/graph/test/test_graphs.cpp (original)
+++ trunk/libs/graph/test/test_graphs.cpp 2009-05-20 12:54:46 EDT (Wed, 20 May 2009)
@@ -150,12 +150,11 @@
         test_graph(g);
     }
     {
- // Make srue that subgraph obeys the basi
         typedef property<edge_index_t, size_t, EdgeBundle> EdgeProp;
         typedef adjacency_list<vecS, vecS, directedS, VertexBundle, EdgeProp> BaseGraph;
         typedef subgraph<BaseGraph> Graph;
         Graph g;
- test_graph(g);
+// test_graph(g);
     }
 }
 

Modified: trunk/libs/graph/test/test_iteration.hpp
==============================================================================
--- trunk/libs/graph/test/test_iteration.hpp (original)
+++ trunk/libs/graph/test/test_iteration.hpp 2009-05-20 12:54:46 EDT (Wed, 20 May 2009)
@@ -16,8 +16,11 @@
 //@{
 template <typename Graph>
 void test_vertex_list_graph(Graph const& g) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((VertexListGraphConcept<Graph>));
+
     std::cout << "...test_vertex_list_graph\n";
- typedef typename boost::graph_traits<Graph>::vertex_iterator Iterator;
+ typedef typename graph_traits<Graph>::vertex_iterator Iterator;
     typedef std::pair<Iterator, Iterator> Range;
 
     Range rng = vertices(g);
@@ -34,12 +37,15 @@
 //@{
 template <typename Graph>
 void test_edge_list_graph(Graph const& g) {
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((EdgeListGraphConcept<Graph>));
+
     std::cout << "...test_edge_list_graph\n";
- typedef typename boost::graph_traits<Graph>::edge_iterator Iterator;
+ typedef typename graph_traits<Graph>::edge_iterator Iterator;
     typedef std::pair<Iterator, Iterator> Range;
 
     Range rng = edges(g);
- BOOST_ASSERT(boost::num_edges(g) == M);
+ BOOST_ASSERT(num_edges(g) == M);
     BOOST_ASSERT(rng.first != rng.second);
     BOOST_ASSERT(std::distance(rng.first, rng.second) == int(M));
 }

Modified: trunk/libs/graph/test/test_properties.hpp
==============================================================================
--- trunk/libs/graph/test/test_properties.hpp (original)
+++ trunk/libs/graph/test/test_properties.hpp 2009-05-20 12:54:46 EDT (Wed, 20 May 2009)
@@ -14,11 +14,12 @@
 //@{
 template <typename Graph, typename VertexSet>
 void test_vertex_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) {
- std::cout << "...test_vertex_bundle\n";
- typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((GraphConcept<Graph>));
+ typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
+ BOOST_CONCEPT_ASSERT((PropertyGraphConcept<Graph, Vertex, vertex_bundle_t>));
 
- // This just has to compile. You can't actually get this map.
- typedef typename boost::property_map<Graph, boost::vertex_bundle_t>::type TestMap;
+ std::cout << "...test_vertex_bundle\n";
 
     // Test bundling via the graph object on the lollipop vertex.
     Vertex v = verts[5];
@@ -27,10 +28,16 @@
     BOOST_ASSERT(g[v].value == 10);
 
     // Test bundling via the property map.
- typedef typename boost::property_map<Graph, int VertexBundle::*>::type BundleMap;
+ typedef typename property_map<Graph, int VertexBundle::*>::type BundleMap;
+ BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept<BundleMap, Vertex>));
     BundleMap map = get(&VertexBundle::value, g);
     put(map, v, 5);
     BOOST_ASSERT(get(map, v) == 5);
+
+ typedef typename property_map<Graph, int VertexBundle::*>::const_type ConstBundleMap;
+ BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept<ConstBundleMap, Vertex>));
+ ConstBundleMap cmap = get(&VertexBundle::value, (Graph const&)g);
+ BOOST_ASSERT(get(cmap, v) == 5);
 }
 
 template <typename Graph, typename VertexSet>
@@ -45,10 +52,12 @@
 //@{
 template <typename Graph, typename VertexSet>
 void test_edge_bundle(Graph& g, VertexSet const& verts, boost::mpl::true_) {
- std::cout << "...test_edge_bundle\n";
- // This just has to compile. You can't actually get this map.
+ using namespace boost;
+ BOOST_CONCEPT_ASSERT((GraphConcept<Graph>));
     typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
- typedef typename boost::property_map<Graph, boost::edge_bundle_t>::type TestMap;
+ BOOST_CONCEPT_ASSERT((PropertyGraphConcept<Graph, Edge, edge_bundle_t>));
+
+ std::cout << "...test_edge_bundle\n";
 
     // Test bundling via the graph object on the lollipop edge.
     Edge e = boost::edge(verts[5], verts[3], g).first;
@@ -58,9 +67,15 @@
 
     // Test bundling via the property map.
     typedef typename boost::property_map<Graph, int EdgeBundle::*>::type BundleMap;
+ BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept<BundleMap, Edge>));
     BundleMap map = get(&EdgeBundle::value, g);
     put(map, e, 5);
     BOOST_ASSERT(get(map, e) == 5);
+
+ typedef typename boost::property_map<Graph, int EdgeBundle::*>::const_type ConstBundleMap;
+ BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept<BundleMap, Edge>));
+ ConstBundleMap cmap = get(&EdgeBundle::value, (Graph const&)g);
+ BOOST_ASSERT(get(cmap, e) == 5);
 }
 
 template <typename Graph, typename VertexSet>


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