From 3009b2303c0712f99b4f14833bf4e2178af2ad22 Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Sat, 22 Sep 2012 20:09:08 +0000 Subject: [PATCH] Checking multiple dimensionalities of graphs [SVN r80641] --- test/grid_graph_cc.cpp | 19 ++++++++---- test/grid_graph_test.cpp | 63 ++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/test/grid_graph_cc.cpp b/test/grid_graph_cc.cpp index a9e1c808..d49de7c3 100644 --- a/test/grid_graph_cc.cpp +++ b/test/grid_graph_cc.cpp @@ -12,14 +12,13 @@ #include #include -#define DIMENSIONS 3 using namespace boost; -int main (int, char*[]) { - - typedef grid_graph Graph; - typedef graph_traits::vertex_descriptor Vertex; - typedef graph_traits::edge_descriptor Edge; +template +void check() { + typedef grid_graph Graph; + typedef typename graph_traits::vertex_descriptor Vertex; + typedef typename graph_traits::edge_descriptor Edge; BOOST_CONCEPT_ASSERT((BidirectionalGraphConcept )); BOOST_CONCEPT_ASSERT((VertexListGraphConcept )); @@ -29,6 +28,14 @@ int main (int, char*[]) { BOOST_CONCEPT_ASSERT((AdjacencyMatrixConcept )); BOOST_CONCEPT_ASSERT((ReadablePropertyGraphConcept )); BOOST_CONCEPT_ASSERT((ReadablePropertyGraphConcept )); +} + +int main (int, char*[]) { + check<0>(); + check<1>(); + check<2>(); + check<3>(); + check<4>(); return (0); } diff --git a/test/grid_graph_test.cpp b/test/grid_graph_test.cpp index 3cd665bd..d88e68d2 100644 --- a/test/grid_graph_test.cpp +++ b/test/grid_graph_test.cpp @@ -17,8 +17,6 @@ #include #include -#define DIMENSIONS 3 - using namespace boost; // Function that prints a vertex to std::cout @@ -28,11 +26,11 @@ void print_vertex(Vertex vertex_to_print) { std::cout << "("; for (std::size_t dimension_index = 0; - dimension_index < DIMENSIONS; + dimension_index < vertex_to_print.size(); ++dimension_index) { std::cout << vertex_to_print[dimension_index]; - if (dimension_index != (DIMENSIONS - 1)) { + if (dimension_index != (vertex_to_print.size() - 1)) { std::cout << ", "; } } @@ -40,31 +38,23 @@ void print_vertex(Vertex vertex_to_print) { std::cout << ")"; } -int test_main(int argc, char* argv[]) { +template +void do_test(minstd_rand& generator) { + typedef grid_graph Graph; + typedef typename graph_traits::vertices_size_type vertices_size_type; + typedef typename graph_traits::edges_size_type edges_size_type; - std::size_t random_seed = time(0); + typedef typename graph_traits::vertex_descriptor vertex_descriptor; + typedef typename graph_traits::edge_descriptor edge_descriptor; - if (argc > 1) { - random_seed = lexical_cast(argv[1]); - } - - minstd_rand generator(random_seed); - - typedef grid_graph Graph; - typedef graph_traits::vertices_size_type vertices_size_type; - typedef graph_traits::edges_size_type edges_size_type; - - typedef graph_traits::vertex_descriptor vertex_descriptor; - typedef graph_traits::edge_descriptor edge_descriptor; - - std::cout << "Dimensions: " << DIMENSIONS << ", lengths: "; + std::cout << "Dimensions: " << Dims << ", lengths: "; // Randomly generate the dimension lengths (3-10) and wrapping - array lengths; - array wrapped; + boost::array lengths; + boost::array wrapped; - for (int dimension_index = 0; - dimension_index < DIMENSIONS; + for (unsigned int dimension_index = 0; + dimension_index < Dims; ++dimension_index) { lengths[dimension_index] = 3 + (generator() % 8); wrapped[dimension_index] = ((generator() % 2) == 0); @@ -78,8 +68,8 @@ int test_main(int argc, char* argv[]) { Graph graph(lengths, wrapped); // Verify dimension lengths and wrapping - for (int dimension_index = 0; - dimension_index < DIMENSIONS; + for (unsigned int dimension_index = 0; + dimension_index < Dims; ++dimension_index) { BOOST_REQUIRE(graph.length(dimension_index) == lengths[dimension_index]); BOOST_REQUIRE(graph.wrapped(dimension_index) == wrapped[dimension_index]); @@ -107,8 +97,8 @@ int test_main(int argc, char* argv[]) { vertices_size_type current_index = get(boost::vertex_index, graph, current_vertex); - for (int dimension_index = 0; - dimension_index < DIMENSIONS; + for (unsigned int dimension_index = 0; + dimension_index < Dims; ++dimension_index) { BOOST_REQUIRE(/*(current_vertex[dimension_index] >= 0) && */ // Always true (current_vertex[dimension_index] < lengths[dimension_index])); @@ -205,6 +195,23 @@ int test_main(int argc, char* argv[]) { } BOOST_REQUIRE(edge_count == num_edges(graph)); +} + +int test_main(int argc, char* argv[]) { + + std::size_t random_seed = time(0); + + if (argc > 1) { + random_seed = lexical_cast(argv[1]); + } + + minstd_rand generator(random_seed); + + do_test<0>(generator); + do_test<1>(generator); + do_test<2>(generator); + do_test<3>(generator); + do_test<4>(generator); return (0); }