test_destruction.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // (C) Copyright 2009 Andrew Sutton
  2. //
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0 (See accompanying file
  5. // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef TEST_DESTRUCTION_HPP
  7. #define TEST_DESTRUCTION_HPP
  8. #include <boost/concept/assert.hpp>
  9. #include <utility>
  10. /** @name Destroy Graph
  11. * Destroy the graph by removing vertices (if possible).
  12. */
  13. //@{
  14. // This will basically catch adjacency matrices, which don't get torn down.
  15. template <typename Graph, typename VertexSet, typename Remove, typename Label>
  16. void destroy_graph(Graph&, VertexSet const&, Remove, Label)
  17. { }
  18. // This matches MutableGraph, so just remove a vertex and then clear.
  19. template <typename Graph, typename VertexSet>
  20. void destroy_graph(Graph& g, VertexSet const& verts, boost::mpl::true_, boost::mpl::false_) {
  21. using namespace boost;
  22. BOOST_CONCEPT_ASSERT((VertexListGraphConcept<Graph>));
  23. BOOST_CONCEPT_ASSERT((VertexMutableGraphConcept<Graph>));
  24. std::cout << "...destroy_normal\n";
  25. // Remove the roof vertex
  26. remove_vertex(verts[0], g);
  27. BOOST_ASSERT(num_vertices(g) == N - 1);
  28. }
  29. // This will match labeled graphs.
  30. template <typename Graph, typename VertexSet>
  31. void destroy_graph(Graph& g, VertexSet const&, boost::mpl::false_, boost::mpl::true_) {
  32. using namespace boost;
  33. BOOST_CONCEPT_ASSERT((VertexListGraphConcept<Graph>));
  34. // BOOST_CONCEPT_ASSERT(( VeretexMutableGraphConcept<Graph> ));
  35. std::cout << "...destroy_labeled\n";
  36. // Remove the roof vertex
  37. remove_vertex(0, g);
  38. BOOST_ASSERT(num_vertices(g) == N - 1);
  39. }
  40. //@}
  41. /** @name Disconnect Graph
  42. * Disconnect edges in the graph. Note that this doesn't fully disconnect the
  43. * graph. It simply determines if we can disconnect an edge or two and verify
  44. * that the resulting graph is valid. The Labeled type parameter is used to
  45. * dispatch for unlabeled and labeled graphs.
  46. *
  47. * @todo This doesn't quite work for multigraphs...
  48. */
  49. //@{
  50. template <typename Graph, typename VertexSet>
  51. void disconnect_graph(Graph& g, VertexSet const& verts, boost::mpl::false_) {
  52. using namespace boost;
  53. BOOST_CONCEPT_ASSERT((EdgeListGraphConcept<Graph>));
  54. BOOST_CONCEPT_ASSERT((EdgeMutableGraphConcept<Graph>));
  55. std::cout << "...disconnect_normal\n";
  56. typedef typename graph_traits<Graph>::edge_descriptor Edge;
  57. // Disconnect the "lollipop" from the house.
  58. Edge e = edge(verts[5], verts[3], g).first;
  59. remove_edge(e, g);
  60. BOOST_ASSERT(num_edges(g) == M - 1);
  61. // Remove the "floor" edge from the house.
  62. remove_edge(verts[3], verts[2], g);
  63. BOOST_ASSERT(num_edges(g) == M - 2);
  64. // Fully disconnect the roof vertex.
  65. clear_vertex(verts[0], g);
  66. BOOST_ASSERT(num_edges(g) == M - 4);
  67. // What happens if we try to remove an edge that doesn't exist?
  68. remove_edge(verts[5], verts[0], g);
  69. BOOST_ASSERT(num_edges(g) == M - 4);
  70. }
  71. template <typename Graph, typename VertexSet>
  72. void disconnect_graph(Graph& g, VertexSet const&, boost::mpl::true_) {
  73. using namespace boost;
  74. BOOST_CONCEPT_ASSERT((EdgeListGraphConcept<Graph>));
  75. // BOOST_CONCEPT_ASSERT((EdgeMutableGraphConcept<Graph>));
  76. std::cout << "...disconnect_labeled\n";
  77. typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
  78. // Disconnect the "lollipop" from the house.
  79. Edge e = boost::edge_by_label(5, 3, g).first;
  80. boost::remove_edge(e, g);
  81. BOOST_ASSERT(boost::num_edges(g) == M - 1);
  82. // Remove the "floor" edge from the house.
  83. boost::remove_edge_by_label(3, 2, g);
  84. BOOST_ASSERT(boost::num_edges(g) == M - 2);
  85. // Fully disconnect the roof vertex.
  86. clear_vertex_by_label(0, g);
  87. BOOST_ASSERT(boost::num_edges(g) == M - 4);
  88. // What happens if we try to remove an edge that doesn't exist?
  89. boost::remove_edge_by_label(5, 0, g);
  90. BOOST_ASSERT(boost::num_edges(g) == M - 4);
  91. }
  92. //@}
  93. #endif