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

source code of boost/libs/graph/test/adj_list_loops.cpp