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