From 34c4c76c66d1a74dcc4215b4cc6565f999a4e386 Mon Sep 17 00:00:00 2001 From: Arnaud Becheler <8360330+Becheler@users.noreply.github.com> Date: Mon, 10 Aug 2026 10:40:39 +0200 Subject: [PATCH 1/2] fix: making tests reproducible --- test/astar_search_test.cpp | 3 +-- test/betweenness_centrality_test.cpp | 2 +- test/bfs.cpp | 2 +- test/biconnected_components_test.cpp | 4 +--- test/boykov_kolmogorov_max_flow_test.cpp | 4 +--- test/bron_kerbosch_all_cliques.cpp | 2 +- test/csr_graph_test.cpp | 10 +++------- test/dfs.cpp | 2 +- test/dijkstra_heap_performance.cpp | 2 +- test/dijkstra_no_color_map_compare.cpp | 8 +------- test/floyd_warshall_test.cpp | 4 ++-- test/generator_test.cpp | 2 +- test/graph.cpp | 2 +- test/grid_graph_test.cpp | 11 ++--------- test/gursoy_atun_layout_test.cpp | 6 +++--- test/incremental_components_test.cpp | 8 +------- test/isomorphism.cpp | 6 +++--- test/layout_test.cpp | 6 +++--- test/matching_test.cpp | 3 +-- test/max_flow_test.cpp | 4 +--- test/mcgregor_subgraphs_test.cpp | 8 +------- test/metric_tsp_approx.cpp | 3 +-- test/property_iter.cpp | 2 +- test/random_matching_test.cpp | 3 +-- test/random_spanning_tree_test.cpp | 2 +- test/subgraph.cpp | 2 +- test/subgraph_bundled.cpp | 2 +- test/tiernan_all_cycles.cpp | 2 +- test/transitive_closure_test.cpp | 3 +-- test/undirected_dfs.cpp | 2 +- test/vf2_sub_graph_iso_test.cpp | 4 ++-- 31 files changed, 42 insertions(+), 82 deletions(-) diff --git a/test/astar_search_test.cpp b/test/astar_search_test.cpp index 756f0cdca..d4a186359 100644 --- a/test/astar_search_test.cpp +++ b/test/astar_search_test.cpp @@ -19,7 +19,6 @@ #include #include #include // for sqrt -#include using namespace boost; using namespace std; @@ -196,7 +195,7 @@ int main(int, char**) } // pick random start/goal - boost::minstd_rand gen(time(0)); + boost::minstd_rand gen(42); vertex start = gen() % num_vertices(g); vertex goal = gen() % num_vertices(g); diff --git a/test/betweenness_centrality_test.cpp b/test/betweenness_centrality_test.cpp index 8a2a02453..3cc1fd8da 100644 --- a/test/betweenness_centrality_test.cpp +++ b/test/betweenness_centrality_test.cpp @@ -237,7 +237,7 @@ void randomly_add_edges(MutableGraph& g, double edge_probability) typedef typename graph_traits< MutableGraph >::directed_category directed_category; - minstd_rand gen; + minstd_rand gen(42); uniform_01< minstd_rand, double > rand_gen(gen); typedef typename graph_traits< MutableGraph >::vertex_descriptor vertex; diff --git a/test/bfs.cpp b/test/bfs.cpp index a3dfad126..be5f45af2 100644 --- a/test/bfs.cpp +++ b/test/bfs.cpp @@ -134,7 +134,7 @@ template < class Graph > struct bfs_test typename Traits::edges_size_type j; typename Traits::vertex_iterator ui, ui_end; - boost::mt19937 gen; + boost::mt19937 gen(42); for (i = 0; i < max_V; ++i) for (j = 0; j < i * i; ++j) diff --git a/test/biconnected_components_test.cpp b/test/biconnected_components_test.cpp index 0990b4ed6..aaead5237 100644 --- a/test/biconnected_components_test.cpp +++ b/test/biconnected_components_test.cpp @@ -123,14 +123,12 @@ int main(int argc, char* argv[]) { std::size_t n = 100; std::size_t m = 500; - std::size_t seed = 1; + std::size_t seed = 42; if (argc > 1) n = lexical_cast< std::size_t >(argv[1]); if (argc > 2) m = lexical_cast< std::size_t >(argv[2]); - if (argc > 3) - seed = lexical_cast< std::size_t >(argv[3]); { Graph g(n); diff --git a/test/boykov_kolmogorov_max_flow_test.cpp b/test/boykov_kolmogorov_max_flow_test.cpp index 9e0ce7b34..d9e7437b6 100644 --- a/test/boykov_kolmogorov_max_flow_test.cpp +++ b/test/boykov_kolmogorov_max_flow_test.cpp @@ -589,14 +589,12 @@ int main(int argc, char* argv[]) { int n_verts = 10; int n_edges = 500; - std::size_t seed = 1; + std::size_t seed = 42; if (argc > 1) n_verts = lexical_cast< int >(argv[1]); if (argc > 2) n_edges = lexical_cast< int >(argv[2]); - if (argc > 3) - seed = lexical_cast< std::size_t >(argv[3]); // we need at least 2 vertices to create src and sink in random graphs // this case is also caught in boykov_kolmogorov_max_flow diff --git a/test/bron_kerbosch_all_cliques.cpp b/test/bron_kerbosch_all_cliques.cpp index 949069a96..0a0967dd1 100644 --- a/test/bron_kerbosch_all_cliques.cpp +++ b/test/bron_kerbosch_all_cliques.cpp @@ -56,7 +56,7 @@ template < typename Graph > void test() static const size_t N = 20; static const double P = 0.1; - boost::minstd_rand rng; + boost::minstd_rand rng(42); Graph g(er(rng, N, P), er(), N); renumber_indices(g); print_edges(g, get(vertex_index, g)); diff --git a/test/csr_graph_test.cpp b/test/csr_graph_test.cpp index 2bf426331..f352426a9 100644 --- a/test/csr_graph_test.cpp +++ b/test/csr_graph_test.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -269,7 +268,7 @@ template < typename OrigGraph > void graph_test(const OrigGraph& g) targets[idx] = target(e, g2); ++idx; } - boost::minstd_rand gen(1); + boost::minstd_rand gen(42); if (num_edges(g) != 0) { for (std::size_t i = num_edges(g) - 1; i > 0; --i) @@ -409,12 +408,9 @@ void test_vertex_and_edge_properties() BOOST_TEST(g[v].centrality == centrality[v]); } -int main(int argc, char* argv[]) +int main() { - // Optionally accept a seed value - int seed = int(std::time(0)); - if (argc > 1) - seed = boost::lexical_cast< int >(argv[1]); + int seed = 42; std::cout << "Seed = " << seed << std::endl; { diff --git a/test/dfs.cpp b/test/dfs.cpp index 64d500f9a..d6b15908d 100644 --- a/test/dfs.cpp +++ b/test/dfs.cpp @@ -120,7 +120,7 @@ template < typename Graph > struct dfs_test typename Traits::edges_size_type j; typename Traits::vertex_iterator vi, vi_end, ui, ui_end; - boost::mt19937 gen; + boost::mt19937 gen(42); for (i = 0; i < max_V; ++i) for (j = 0; j < i * i; ++j) diff --git a/test/dijkstra_heap_performance.cpp b/test/dijkstra_heap_performance.cpp index 89aaa38bc..6c6b9ed0b 100644 --- a/test/dijkstra_heap_performance.cpp +++ b/test/dijkstra_heap_performance.cpp @@ -84,7 +84,7 @@ int main(int argc, char* argv[]) { unsigned n = (argc > 1 ? lexical_cast< unsigned >(argv[1]) : 10000u); unsigned m = (argc > 2 ? lexical_cast< unsigned >(argv[2]) : 10 * n); - int seed = (argc > 3 ? lexical_cast< int >(argv[3]) : 1); + int seed = 42; // Build random graph typedef adjacency_list< vecS, vecS, directedS, no_property, diff --git a/test/dijkstra_no_color_map_compare.cpp b/test/dijkstra_no_color_map_compare.cpp index 0762b2069..5cd9863aa 100644 --- a/test/dijkstra_no_color_map_compare.cpp +++ b/test/dijkstra_no_color_map_compare.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #ifdef BOOST_MSVC @@ -81,7 +80,7 @@ int main(int argc, char* argv[]) int vertices_to_create = 10; int edges_to_create = 500; - std::size_t random_seed = std::time(0); + std::size_t random_seed = 42; if (argc > 1) { @@ -93,11 +92,6 @@ int main(int argc, char* argv[]) edges_to_create = lexical_cast< int >(argv[2]); } - if (argc > 3) - { - random_seed = lexical_cast< std::size_t >(argv[3]); - } - minstd_rand generator(random_seed); // Set up graph diff --git a/test/floyd_warshall_test.cpp b/test/floyd_warshall_test.cpp index 0cc99ca9f..527eefbf1 100644 --- a/test/floyd_warshall_test.cpp +++ b/test/floyd_warshall_test.cpp @@ -28,7 +28,7 @@ template < typename T > inline const T& my_min(const T& x, const T& y) template < typename Graph > bool acceptance_test(Graph& g, int vec, int e) { - boost::minstd_rand ran(vec); + boost::minstd_rand ran(42); { typename boost::property_map< Graph, boost::vertex_name_t >::type index @@ -226,7 +226,7 @@ template < typename Graph > bool acceptance_test(Graph& g, int vec, int e) template < typename Graph > bool acceptance_test2(Graph& g, int vec, int e) { - boost::minstd_rand ran(vec); + boost::minstd_rand ran(42); { diff --git a/test/generator_test.cpp b/test/generator_test.cpp index 340d1954d..e433c07be 100644 --- a/test/generator_test.cpp +++ b/test/generator_test.cpp @@ -27,7 +27,7 @@ int main(int argc, char** argv) typedef adjacency_list< vecS, vecS, directedS > Graph; - RandomGenerator gen; + RandomGenerator gen(42); size_t N = 100; size_t M = 1000; diff --git a/test/graph.cpp b/test/graph.cpp index 596c3a7d6..7d4d9383d 100644 --- a/test/graph.cpp +++ b/test/graph.cpp @@ -178,7 +178,7 @@ int main(int, char*[]) add_vertex(current_vertex_id++, g); // also need to test EdgeIterator graph constructor -JGS - mt19937 gen; + mt19937 gen(42); for (j = 0; j < 10; ++j) { diff --git a/test/grid_graph_test.cpp b/test/grid_graph_test.cpp index 7faff8df2..6ee865a45 100644 --- a/test/grid_graph_test.cpp +++ b/test/grid_graph_test.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -222,15 +221,9 @@ template < unsigned int Dims > void do_test(minstd_rand& generator) BOOST_TEST(edge_count == num_edges(graph)); } -int main(int argc, char* argv[]) +int main() { - - std::size_t random_seed = std::time(0); - - if (argc > 1) - { - random_seed = lexical_cast< std::size_t >(argv[1]); - } + std::size_t random_seed = 42; minstd_rand generator(random_seed); diff --git a/test/gursoy_atun_layout_test.cpp b/test/gursoy_atun_layout_test.cpp index d7d578fdb..520309c04 100644 --- a/test/gursoy_atun_layout_test.cpp +++ b/test/gursoy_atun_layout_test.cpp @@ -66,7 +66,7 @@ int main(int, char*[]) // Make grid, like Gursoy and Atun used std::map< int, std::map< int, vertex_descriptor > > verts; const int grid_size = 20; - boost::minstd_rand edge_weight_gen; + boost::minstd_rand edge_weight_gen(42); boost::uniform_01< boost::minstd_rand > random_edge_weight(edge_weight_gen); for (int i = 0; i < grid_size; ++i) for (int j = 0; j < grid_size; ++j) @@ -99,7 +99,7 @@ int main(int, char*[]) int n = 10000; double alpha = 0.4; double beta = 50; - minstd_rand gen; + minstd_rand gen(42); graph_type graph(plod_iterator(gen, n, alpha, beta), plod_iterator(), n); @@ -107,7 +107,7 @@ int main(int, char*[]) int n = 1000; int k = 6; double p = 0.001; - minstd_rand gen; + minstd_rand gen(42); graph_type graph(small_world_iterator< minstd_rand >(gen, n, k, p), small_world_iterator< minstd_rand >(n, k), n); #endif diff --git a/test/incremental_components_test.cpp b/test/incremental_components_test.cpp index df833be9f..531cf9d16 100644 --- a/test/incremental_components_test.cpp +++ b/test/incremental_components_test.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -128,7 +127,7 @@ template < typename Graph > void test_graph(const Graph& graph) int main(int argc, char* argv[]) { std::size_t vertices_to_generate = 100, edges_to_generate = 50, - random_seed = std::time(0); + random_seed = 42; // Parse command-line arguments @@ -142,11 +141,6 @@ int main(int argc, char* argv[]) edges_to_generate = lexical_cast< std::size_t >(argv[2]); } - if (argc > 3) - { - random_seed = lexical_cast< std::size_t >(argv[3]); - } - minstd_rand generator(random_seed); // Generate random vector and list graphs diff --git a/test/isomorphism.cpp b/test/isomorphism.cpp index 7aeae2818..a61f8db7d 100644 --- a/test/isomorphism.cpp +++ b/test/isomorphism.cpp @@ -74,7 +74,7 @@ randomly_permute_graph(const Graph1& g1, Graph2& g2) typedef typename graph_traits< Graph2 >::vertex_descriptor vertex2; typedef typename graph_traits< Graph1 >::edge_iterator edge_iterator; - random_generator_type gen; + random_generator_type gen(42); // Decide new order std::vector< vertex1 > orig_vertices; @@ -100,7 +100,7 @@ template < typename Graph > void generate_random_digraph(Graph& g, double edge_probability) { typedef typename graph_traits< Graph >::vertex_iterator vertex_iterator; - random_generator_type random_gen; + random_generator_type random_gen(42); boost::uniform_real< double > distrib(0.0, 1.0); boost::variate_generator< random_generator_type&, boost::uniform_real< double > > @@ -292,7 +292,7 @@ void test_colored_isomorphism(int n, double edge_probability) std::fill(colors.begin(), midpoint, 0); std::fill(midpoint, colors.end(), 1); - random_generator_type gen; + random_generator_type gen(42); std::shuffle(colors.begin(), colors.end(), gen); diff --git a/test/layout_test.cpp b/test/layout_test.cpp index 52b07647e..2108ac87b 100644 --- a/test/layout_test.cpp +++ b/test/layout_test.cpp @@ -230,7 +230,7 @@ template < typename Graph > void test_cube(Graph*) dump_graph_layout("cube", g, get(vertex_position, g)); - minstd_rand gen; + minstd_rand gen(42); typedef square_topology<> Topology; Topology topology(gen, 50.0); std::vector< Topology::point_difference_type > displacements( @@ -291,7 +291,7 @@ template < typename Graph > void test_triangular(Graph*) std::cerr << std::endl; typedef square_topology<> Topology; - minstd_rand gen; + minstd_rand gen(42); Topology topology(gen, 50.0); Topology::point_type origin; origin[0] = origin[1] = 50.0; @@ -371,7 +371,7 @@ template < typename Graph > void test_disconnected(Graph*) kamada_kawai_done()); BOOST_TEST(!ok); - minstd_rand gen; + minstd_rand gen(42); rectangle_topology<> rect_top(gen, -25, -25, 25, 25); random_graph_layout(g, get(vertex_position, g), rect_top); diff --git a/test/matching_test.cpp b/test/matching_test.cpp index 275ad3460..c4b566203 100644 --- a/test/matching_test.cpp +++ b/test/matching_test.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -309,7 +308,7 @@ void matching_test(std::size_t num_v, const std::string& graph_name) vertex_index_installer< Graph >::install(j); typedef boost::mt19937 base_generator_type; - base_generator_type generator(static_cast< unsigned int >(std::time(0))); + base_generator_type generator(42); boost::uniform_int<> distribution(0, double_num_v - 1); boost::variate_generator< base_generator_type&, boost::uniform_int<> > rand_num(generator, distribution); diff --git a/test/max_flow_test.cpp b/test/max_flow_test.cpp index 14e5d77d0..014067ab2 100644 --- a/test/max_flow_test.cpp +++ b/test/max_flow_test.cpp @@ -77,14 +77,12 @@ int main(int argc, char* argv[]) graph_traits< Graph >::vertices_size_type n_verts = 100; graph_traits< Graph >::edges_size_type n_edges = 1000; - std::size_t seed = 1; + std::size_t seed = 42; if (argc > 1) n_verts = lexical_cast< std::size_t >(argv[1]); if (argc > 2) n_edges = lexical_cast< std::size_t >(argv[2]); - if (argc > 3) - seed = lexical_cast< std::size_t >(argv[3]); Graph g; const int cap_low = 1; diff --git a/test/mcgregor_subgraphs_test.cpp b/test/mcgregor_subgraphs_test.cpp index 5409dbf15..c029a7cb5 100644 --- a/test/mcgregor_subgraphs_test.cpp +++ b/test/mcgregor_subgraphs_test.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include @@ -312,7 +311,7 @@ int main(int argc, char* argv[]) { int vertices_to_create = 10; int max_edges_per_vertex = 2; - std::size_t random_seed = std::time(0); + std::size_t random_seed = 42; if (argc > 1) { @@ -329,11 +328,6 @@ int main(int argc, char* argv[]) output_graphs = boost::lexical_cast< bool >(argv[3]); } - if (argc > 4) - { - random_seed = boost::lexical_cast< std::size_t >(argv[4]); - } - boost::minstd_rand generator(random_seed); // Using a vecS graph here so that we don't have to mess around with diff --git a/test/metric_tsp_approx.cpp b/test/metric_tsp_approx.cpp index fda070729..e93a503b1 100644 --- a/test/metric_tsp_approx.cpp +++ b/test/metric_tsp_approx.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -90,7 +89,7 @@ void testScalability(unsigned numpts) typedef set< simple_point< double >, cmpPnt< double > > PointSet; typedef vector< Vertex > Container; - boost::mt19937 rng(std::time(0)); + boost::mt19937 rng(42); uniform_real<> range(0.01, (numpts * 2)); variate_generator< boost::mt19937&, uniform_real<> > pnt_gen(rng, range); diff --git a/test/property_iter.cpp b/test/property_iter.cpp index 09a116db0..8a2912277 100644 --- a/test/property_iter.cpp +++ b/test/property_iter.cpp @@ -80,7 +80,7 @@ int main(int, char*[]) for (std::size_t k = 0; k < N; ++k) add_vertex(current_vertex_id++, g); - mt19937 gen; + mt19937 gen(42); for (j = 0; j < 10; ++j) { diff --git a/test/random_matching_test.cpp b/test/random_matching_test.cpp index 34de16108..a16a90b88 100644 --- a/test/random_matching_test.cpp +++ b/test/random_matching_test.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -48,7 +47,7 @@ int main(int argc, char** argv) undirected_graph g(n); typedef boost::mt19937 base_generator_type; - base_generator_type generator(static_cast< unsigned int >(std::time(0))); + base_generator_type generator(42); boost::uniform_int<> distribution(0, n - 1); boost::variate_generator< base_generator_type&, boost::uniform_int<> > rand_num(generator, distribution); diff --git a/test/random_spanning_tree_test.cpp b/test/random_spanning_tree_test.cpp index bcd40d183..c0974d253 100644 --- a/test/random_spanning_tree_test.cpp +++ b/test/random_spanning_tree_test.cpp @@ -77,7 +77,7 @@ int main(int, char**) put(weight, e, (1. + get(edge_index, g, e)) / num_edges(g)); } - boost::mt19937 gen; + boost::mt19937 gen(42); random_spanning_tree(g, gen, predecessor_map(pred)); // write_spanning_tree(g, pred, constant_property_map(1.), "unweight_random_st.dot"); diff --git a/test/subgraph.cpp b/test/subgraph.cpp index 50168a7a0..655baa3a7 100644 --- a/test/subgraph.cpp +++ b/test/subgraph.cpp @@ -54,7 +54,7 @@ int main(int, char*[]) typedef subgraph< graph_t > subgraph_t; typedef graph_traits< subgraph_t >::vertex_descriptor vertex_t; - mt19937 gen; + mt19937 gen(42); for (int t = 0; t < 100; t += 5) { subgraph_t g; diff --git a/test/subgraph_bundled.cpp b/test/subgraph_bundled.cpp index 14bf527e4..8cbf7c1d6 100644 --- a/test/subgraph_bundled.cpp +++ b/test/subgraph_bundled.cpp @@ -37,7 +37,7 @@ typedef graph_traits< Subgraph >::edge_iterator EdgeIter; int main(int, char*[]) { - mt19937 gen; + mt19937 gen(42); for (int t = 0; t < 100; t += 5) { Subgraph g; diff --git a/test/tiernan_all_cycles.cpp b/test/tiernan_all_cycles.cpp index 6705bb7e9..41431cd8b 100644 --- a/test/tiernan_all_cycles.cpp +++ b/test/tiernan_all_cycles.cpp @@ -49,7 +49,7 @@ template < typename Graph > void test() // of edge connection. static const size_t N = 20; static const double P = 0.1; - boost::minstd_rand rng; + boost::minstd_rand rng(42); Graph g(er(rng, N, P), er(), N); renumber_indices(g); diff --git a/test/transitive_closure_test.cpp b/test/transitive_closure_test.cpp index 8698a928e..066e2a72c 100644 --- a/test/transitive_closure_test.cpp +++ b/test/transitive_closure_test.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -158,7 +157,7 @@ bool test(int n, double p) int main() { - srand(time(0)); + srand(42); static class { public: diff --git a/test/undirected_dfs.cpp b/test/undirected_dfs.cpp index 8d2f86465..097d53420 100644 --- a/test/undirected_dfs.cpp +++ b/test/undirected_dfs.cpp @@ -126,7 +126,7 @@ template < typename Graph > struct dfs_test typename Traits::vertex_iterator vi, vi_end, ui, ui_end; typename Traits::edge_iterator ei, ei_end; - boost::mt19937 gen; + boost::mt19937 gen(42); for (i = 0; i < max_V; ++i) for (j = 0; j < i * i; ++j) diff --git a/test/vf2_sub_graph_iso_test.cpp b/test/vf2_sub_graph_iso_test.cpp index 01020e955..f36139fb1 100644 --- a/test/vf2_sub_graph_iso_test.cpp +++ b/test/vf2_sub_graph_iso_test.cpp @@ -67,7 +67,7 @@ void randomly_permute_graph(Graph1& g1, const Graph2& g2) typedef typename graph_traits< Graph1 >::vertex_iterator vertex_iterator; typedef typename graph_traits< Graph2 >::edge_iterator edge_iterator; - random_generator_type gen; + random_generator_type gen(42); // Decide new order std::vector< vertex2 > orig_vertices; @@ -109,7 +109,7 @@ void generate_random_digraph(Graph& g, double edge_probability, BOOST_TEST(0 <= max_vertex_name); typedef typename graph_traits< Graph >::vertex_iterator vertex_iterator; - random_generator_type random_gen; + random_generator_type random_gen(42); boost::uniform_real< double > dist_real(0.0, 1.0); boost::variate_generator< random_generator_type&, boost::uniform_real< double > > From bc05361cfdd51d5f2f05c5f099d69643208c9b08 Mon Sep 17 00:00:00 2001 From: Arnaud Becheler <8360330+Becheler@users.noreply.github.com> Date: Mon, 10 Aug 2026 12:58:48 +0200 Subject: [PATCH 2/2] fix: this entire file was untested, added a bunch of invariants --- test/Jamfile.v2 | 2 +- test/metric_tsp_approx.cpp | 73 ++++++++---------------------------- test/metric_tsp_approx.graph | 8 ---- 3 files changed, 16 insertions(+), 67 deletions(-) delete mode 100644 test/metric_tsp_approx.graph diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 0ef7513fe..1f5796fab 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -135,7 +135,7 @@ alias graph_test_regular : [ run rcsp_custom_vertex_id.cpp ] [ run rcsp_single_solution.cpp ] [ run is_straight_line_draw_test.cpp ] - [ run metric_tsp_approx.cpp /boost/timer//boost_timer : metric_tsp_approx.graph : : ] + [ run metric_tsp_approx.cpp /boost/timer//boost_timer ] [ compile dimacs.cpp ] [ run bron_kerbosch_all_cliques.cpp ] [ run tiernan_all_cycles.cpp ] diff --git a/test/metric_tsp_approx.cpp b/test/metric_tsp_approx.cpp index e93a503b1..9d7b03d52 100644 --- a/test/metric_tsp_approx.cpp +++ b/test/metric_tsp_approx.cpp @@ -7,13 +7,12 @@ // http://www.boost.org/LICENSE_1_0.txt) //======================================================================= +#include #include #include -#include #include -#include -#include +#include #include #include #include @@ -23,9 +22,6 @@ #include #include -// TODO: Integrate this into the test system a little better. We need to run -// the test with some kind of input file. - template < typename PointType > struct cmpPnt { bool operator()(const boost::simple_point< PointType >& l, @@ -173,23 +169,7 @@ template < typename PositionVec > void checkAdjList(PositionVec v) c.clear(); } -static void usage() -{ - using namespace std; - cerr << "To run this program properly please place a " - << "file called graph.txt" << endl - << "into the current working directory." << endl - << "Each line of this file should be a coordinate specifying the" - << endl - << "location of a vertex" << endl - << "For example: " << endl - << "1,2" << endl - << "20,4" << endl - << "15,7" << endl - << endl; -} - -int main(int argc, char* argv[]) +int main() { using namespace boost; using namespace std; @@ -203,43 +183,18 @@ int main(int argc, char* argv[]) typedef property_map< Graph, edge_weight_t >::type WeightMap; typedef property_map< Graph, vertex_index_t >::type VertexMap; - // Make sure that the the we can parse the given file. - if (argc < 2) - { - usage(); - // return -1; - return 0; - } - - // Open the graph file, failing if one isn't given on the command line. - ifstream fin(argv[1]); - if (!fin) - { - usage(); - // return -1; - return 0; - } + static const double coords[][2] = { { 2, 5 }, { 2, 3 }, { 1, 2 }, + { 4, 5 }, { 5, 4 }, { 4, 3 }, { 6, 3 }, { 3, 1 } }; - string line; PositionVec position_vec; - - int n(0); - while (getline(fin, line)) + for (size_t i = 0; i < sizeof(coords) / sizeof(coords[0]); ++i) { simple_point< double > vertex; - - size_t idx(line.find(",")); - string xStr(line.substr(0, idx)); - string yStr(line.substr(idx + 1, line.size() - idx)); - - vertex.x = lexical_cast< double >(xStr); - vertex.y = lexical_cast< double >(yStr); - + vertex.x = coords[i][0]; + vertex.y = coords[i][1]; position_vec.push_back(vertex); - n++; } - - fin.close(); + int n(static_cast< int >(position_vec.size())); Container c; Graph g(position_vec.size()); @@ -285,10 +240,12 @@ int main(int argc, char* argv[]) return -1; } - cout << "Number of points: " << num_vertices(g) << endl; - cout << "Number of edges: " << num_edges(g) << endl; cout << "Length of Tour: " << len << endl; + BOOST_TEST_EQ(num_vertices(g), size_t(8)); + BOOST_TEST_EQ(c.size(), num_vertices(g) + 1); + BOOST_TEST(std::abs(len - 19.073950245236318) < 1e-9); + int cnt(0); pair< Vertex, Vertex > triangleEdge; for (vector< Vertex >::iterator itr = c.begin(); itr != c.end(); @@ -326,7 +283,7 @@ int main(int argc, char* argv[]) { caught = true; } - BOOST_ASSERT(caught); + BOOST_TEST(caught); - return 0; + return boost::report_errors(); } diff --git a/test/metric_tsp_approx.graph b/test/metric_tsp_approx.graph deleted file mode 100644 index 1af437ac6..000000000 --- a/test/metric_tsp_approx.graph +++ /dev/null @@ -1,8 +0,0 @@ -2,5 -2,3 -1,2 -4,5 -5,4 -4,3 -6,3 -3,1 \ No newline at end of file