adj_list_loops.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // (C) Copyright Andrew Sutton 2009
  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. #include <iostream>
  7. #include <boost/assert.hpp>
  8. #include <boost/graph/adjacency_list.hpp>
  9. using namespace boost;
  10. // TODO: Integrate this into a larger adj_list test suite.
  11. template <typename Graph>
  12. void test_graph_nonloop()
  13. {
  14. typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
  15. // Build a graph with 1 edge and turn it into a loop.
  16. Graph g(5);
  17. Vertex u = *vertices(g).first;
  18. Vertex v = *next(vertices(g).first, 2);
  19. add_edge(u, v, g);
  20. BOOST_ASSERT(num_vertices(g) == 5);
  21. BOOST_ASSERT(num_edges(g) == 1);
  22. remove_edge(u, v, g);
  23. BOOST_ASSERT(num_edges(g) == 0);
  24. }
  25. template <typename Graph>
  26. void test_multigraph_nonloop()
  27. {
  28. typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
  29. // Build a graph with 1 edge and turn it into a loop.
  30. Graph g(5);
  31. Vertex u = *vertices(g).first;
  32. Vertex v = *next(vertices(g).first, 2);
  33. add_edge(u, v, g);
  34. add_edge(u, v, g);
  35. BOOST_ASSERT(num_vertices(g) == 5);
  36. BOOST_ASSERT(num_edges(g) == 2);
  37. remove_edge(u, v, g);
  38. BOOST_ASSERT(num_edges(g) == 0);
  39. }
  40. template <typename Graph>
  41. void test_graph_loop()
  42. {
  43. typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
  44. Graph g(5);
  45. Vertex v = *next(vertices(g).first, 2);
  46. add_edge(v, v, g);
  47. BOOST_ASSERT(num_vertices(g) == 5);
  48. BOOST_ASSERT(num_edges(g) == 1);
  49. remove_edge(v, v, g);
  50. BOOST_ASSERT(num_edges(g) == 0);
  51. }
  52. template <typename Graph>
  53. void test_multigraph_loop()
  54. {
  55. typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
  56. Graph g(5);
  57. Vertex v = *next(vertices(g).first, 2);
  58. add_edge(v, v, g);
  59. add_edge(v, v, g);
  60. BOOST_ASSERT(num_vertices(g) == 5);
  61. BOOST_ASSERT(num_edges(g) == 2);
  62. remove_edge(v, v, g);
  63. BOOST_ASSERT(num_edges(g) == 0);
  64. }
  65. template <typename Kind>
  66. void test()
  67. {
  68. typedef no_property na;
  69. typedef adjacency_list<vecS, vecS, Kind, na, na, na, listS> VVL;
  70. typedef adjacency_list<listS, vecS, Kind, na, na, na, listS> LVL;
  71. typedef adjacency_list<setS, vecS, Kind, na, na, na, listS> SVL;
  72. typedef adjacency_list<multisetS, vecS, Kind, na, na, na, listS> MVL;
  73. test_graph_nonloop<VVL>();
  74. test_graph_nonloop<LVL>();
  75. test_graph_nonloop<SVL>();
  76. test_graph_nonloop<MVL>();
  77. test_multigraph_nonloop<VVL>();
  78. test_multigraph_nonloop<LVL>();
  79. test_multigraph_nonloop<MVL>();
  80. test_graph_loop<VVL>();
  81. test_graph_loop<LVL>();
  82. test_graph_loop<SVL>();
  83. test_graph_loop<MVL>();
  84. test_multigraph_loop<VVL>();
  85. test_multigraph_loop<LVL>();
  86. test_multigraph_loop<MVL>();
  87. }
  88. int main()
  89. {
  90. test<undirectedS>();
  91. test<directedS>();
  92. test<bidirectionalS>();
  93. return 0;
  94. }