test_graphs.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // (C) Copyright 2009-2010 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. #include <iostream>
  7. #include "typestr.hpp"
  8. #include <boost/graph/adjacency_list.hpp>
  9. #include <boost/graph/adjacency_matrix.hpp>
  10. #include <boost/graph/undirected_graph.hpp>
  11. #include <boost/graph/directed_graph.hpp>
  12. #include <boost/graph/compressed_sparse_row_graph.hpp>
  13. #include <boost/graph/labeled_graph.hpp>
  14. #include <boost/graph/subgraph.hpp>
  15. #include "test_graph.hpp"
  16. // This test module is a testing ground to determine if graphs and graph
  17. // adaptors actually implement the graph concepts correctly.
  18. using namespace boost;
  19. int main()
  20. {
  21. // Bootstrap all of the tests by declaring a kind graph and asserting some
  22. // basic properties about it.
  23. {
  24. typedef undirected_graph<VertexBundle, EdgeBundle, GraphBundle> Graph;
  25. BOOST_META_ASSERT(is_undirected_graph<Graph>);
  26. BOOST_META_ASSERT(is_multigraph<Graph>);
  27. BOOST_META_ASSERT(is_incidence_graph<Graph>);
  28. BOOST_META_ASSERT(is_bidirectional_graph<Graph>);
  29. BOOST_META_ASSERT(has_vertex_property<Graph>);
  30. BOOST_META_ASSERT(has_bundled_vertex_property<Graph>);
  31. BOOST_META_ASSERT(has_edge_property<Graph>);
  32. BOOST_META_ASSERT(has_bundled_edge_property<Graph>);
  33. BOOST_META_ASSERT(is_mutable_graph<Graph>);
  34. BOOST_META_ASSERT(is_mutable_property_graph<Graph>);
  35. Graph g;
  36. test_graph(g);
  37. }
  38. {
  39. typedef directed_graph<VertexBundle, EdgeBundle, GraphBundle> Graph;
  40. BOOST_META_ASSERT(is_directed_graph<Graph>);
  41. BOOST_META_ASSERT(is_multigraph<Graph>);
  42. BOOST_META_ASSERT(is_incidence_graph<Graph>);
  43. BOOST_META_ASSERT(is_bidirectional_graph<Graph>);
  44. BOOST_META_ASSERT(is_directed_bidirectional_graph<Graph>);
  45. BOOST_META_ASSERT(has_vertex_property<Graph>);
  46. BOOST_META_ASSERT(has_bundled_vertex_property<Graph>);
  47. BOOST_META_ASSERT(has_edge_property<Graph>);
  48. BOOST_META_ASSERT(has_bundled_edge_property<Graph>);
  49. BOOST_META_ASSERT(is_mutable_graph<Graph>);
  50. BOOST_META_ASSERT(is_mutable_property_graph<Graph>);
  51. Graph g;
  52. test_graph(g);
  53. }
  54. {
  55. typedef adjacency_list<vecS, vecS, undirectedS, VertexBundle, EdgeBundle, GraphBundle> Graph;
  56. BOOST_META_ASSERT(is_undirected_graph<Graph>);
  57. BOOST_META_ASSERT(is_multigraph<Graph>);
  58. BOOST_META_ASSERT(is_incidence_graph<Graph>);
  59. BOOST_META_ASSERT(is_bidirectional_graph<Graph>);
  60. BOOST_META_ASSERT(has_vertex_property<Graph>);
  61. BOOST_META_ASSERT(has_bundled_vertex_property<Graph>);
  62. BOOST_META_ASSERT(has_edge_property<Graph>);
  63. BOOST_META_ASSERT(has_bundled_edge_property<Graph>);
  64. BOOST_META_ASSERT(is_add_only_property_graph<Graph>);
  65. Graph g;
  66. test_graph(g);
  67. }
  68. {
  69. typedef adjacency_list<vecS, vecS, directedS, VertexBundle, EdgeBundle, GraphBundle> Graph;
  70. Graph g;
  71. BOOST_META_ASSERT(is_directed_graph<Graph>);
  72. BOOST_META_ASSERT(is_multigraph<Graph>);
  73. BOOST_META_ASSERT(is_incidence_graph<Graph>);
  74. BOOST_META_ASSERT(!is_bidirectional_graph<Graph>);
  75. BOOST_META_ASSERT(is_directed_unidirectional_graph<Graph>);
  76. BOOST_META_ASSERT(has_vertex_property<Graph>);
  77. BOOST_META_ASSERT(has_bundled_vertex_property<Graph>);
  78. BOOST_META_ASSERT(has_edge_property<Graph>);
  79. BOOST_META_ASSERT(has_bundled_edge_property<Graph>);
  80. BOOST_META_ASSERT(is_add_only_property_graph<Graph>);
  81. test_graph(g);
  82. }
  83. {
  84. // Common bidi adjlist
  85. typedef adjacency_list<vecS, vecS, bidirectionalS, VertexBundle, EdgeBundle, GraphBundle> Graph;
  86. BOOST_META_ASSERT(is_directed_graph<Graph>);
  87. BOOST_META_ASSERT(is_multigraph<Graph>);
  88. BOOST_META_ASSERT(is_incidence_graph<Graph>);
  89. BOOST_META_ASSERT(is_bidirectional_graph<Graph>);
  90. BOOST_META_ASSERT(is_directed_bidirectional_graph<Graph>);
  91. BOOST_META_ASSERT(has_vertex_property<Graph>);
  92. BOOST_META_ASSERT(has_bundled_vertex_property<Graph>);
  93. BOOST_META_ASSERT(has_edge_property<Graph>);
  94. BOOST_META_ASSERT(has_bundled_edge_property<Graph>);
  95. BOOST_META_ASSERT(is_add_only_property_graph<Graph>);
  96. Graph g;
  97. test_graph(g);
  98. }
  99. {
  100. // Same as above, but testing VL==listS
  101. typedef adjacency_list<vecS, listS, bidirectionalS, VertexBundle, EdgeBundle, GraphBundle> Graph;
  102. BOOST_META_ASSERT(is_directed_graph<Graph>);
  103. BOOST_META_ASSERT(is_multigraph<Graph>);
  104. BOOST_META_ASSERT(is_incidence_graph<Graph>);
  105. BOOST_META_ASSERT(is_bidirectional_graph<Graph>);
  106. BOOST_META_ASSERT(is_directed_bidirectional_graph<Graph>);
  107. BOOST_META_ASSERT(has_vertex_property<Graph>);
  108. BOOST_META_ASSERT(has_bundled_vertex_property<Graph>);
  109. BOOST_META_ASSERT(has_edge_property<Graph>);
  110. BOOST_META_ASSERT(has_bundled_edge_property<Graph>);
  111. BOOST_META_ASSERT(is_mutable_property_graph<Graph>);
  112. Graph g;
  113. test_graph(g);
  114. }
  115. {
  116. typedef adjacency_matrix<directedS, VertexBundle, EdgeBundle, GraphBundle> Graph;
  117. BOOST_META_ASSERT(is_directed_graph<Graph>);
  118. BOOST_META_ASSERT(!is_multigraph<Graph>);
  119. BOOST_META_ASSERT(has_vertex_property<Graph>);
  120. BOOST_META_ASSERT(has_bundled_vertex_property<Graph>);
  121. BOOST_META_ASSERT(has_edge_property<Graph>);
  122. BOOST_META_ASSERT(has_bundled_edge_property<Graph>);
  123. BOOST_META_ASSERT(is_mutable_edge_graph<Graph>);
  124. BOOST_META_ASSERT(is_mutable_edge_property_graph<Graph>);
  125. Graph g(N);
  126. test_graph(g);
  127. }
  128. {
  129. typedef adjacency_matrix<directedS, VertexBundle, EdgeBundle> Graph;
  130. BOOST_META_ASSERT(is_directed_graph<Graph>);
  131. BOOST_META_ASSERT(!is_multigraph<Graph>);
  132. BOOST_META_ASSERT(has_vertex_property<Graph>);
  133. BOOST_META_ASSERT(has_bundled_vertex_property<Graph>);
  134. BOOST_META_ASSERT(has_edge_property<Graph>);
  135. BOOST_META_ASSERT(has_bundled_edge_property<Graph>);
  136. BOOST_META_ASSERT(is_mutable_edge_graph<Graph>);
  137. BOOST_META_ASSERT(is_mutable_edge_property_graph<Graph>);
  138. Graph g(N);
  139. test_graph(g);
  140. }
  141. {
  142. typedef labeled_graph<directed_graph<>, unsigned> Graph;
  143. BOOST_META_ASSERT(is_directed_graph<Graph>);
  144. BOOST_META_ASSERT(is_multigraph<Graph>);
  145. BOOST_META_ASSERT(is_incidence_graph<Graph>);
  146. BOOST_META_ASSERT(is_bidirectional_graph<Graph>);
  147. BOOST_META_ASSERT(is_directed_bidirectional_graph<Graph>);
  148. BOOST_META_ASSERT(is_labeled_mutable_property_graph<Graph>);
  149. BOOST_META_ASSERT(is_labeled_graph<Graph>);
  150. BOOST_META_ASSERT(!has_vertex_property<Graph>);
  151. BOOST_META_ASSERT(!has_bundled_vertex_property<Graph>);
  152. BOOST_META_ASSERT(!has_edge_property<Graph>);
  153. BOOST_META_ASSERT(!has_bundled_edge_property<Graph>);
  154. BOOST_META_ASSERT(is_labeled_mutable_graph<Graph>);
  155. Graph g;
  156. test_graph(g);
  157. }
  158. // FIXME: CSR doesn't have mutability traits so we can't generalize the
  159. // constructions of the required graph. Just assert the properties for now.
  160. // NOTE: CSR graphs are also atypical in that they don't have "normal"
  161. // vertex and edge properties. They're "abnormal" in the sense that they have
  162. // a valid bundled type, but the property types are no_property.
  163. {
  164. typedef compressed_sparse_row_graph<
  165. directedS, VertexBundle, EdgeBundle, GraphBundle
  166. > Graph;
  167. BOOST_META_ASSERT(is_directed_graph<Graph>);
  168. BOOST_META_ASSERT(is_multigraph<Graph>);
  169. BOOST_META_ASSERT(has_graph_property<Graph>);
  170. BOOST_META_ASSERT(has_bundled_graph_property<Graph>);
  171. BOOST_META_ASSERT(!has_vertex_property<Graph>);
  172. BOOST_META_ASSERT(has_bundled_vertex_property<Graph>);
  173. BOOST_META_ASSERT(!has_edge_property<Graph>);
  174. BOOST_META_ASSERT(has_bundled_edge_property<Graph>);
  175. }
  176. {
  177. typedef compressed_sparse_row_graph<
  178. bidirectionalS, VertexBundle, EdgeBundle, GraphBundle
  179. > Graph;
  180. BOOST_META_ASSERT(is_directed_graph<Graph>);
  181. BOOST_META_ASSERT(is_multigraph<Graph>);
  182. BOOST_META_ASSERT(has_graph_property<Graph>);
  183. BOOST_META_ASSERT(has_bundled_graph_property<Graph>);
  184. BOOST_META_ASSERT(!has_vertex_property<Graph>);
  185. BOOST_META_ASSERT(has_bundled_vertex_property<Graph>);
  186. BOOST_META_ASSERT(!has_edge_property<Graph>);
  187. BOOST_META_ASSERT(has_bundled_edge_property<Graph>);
  188. }
  189. // TODO: What other kinds of graphs do we have here...
  190. }