File: adj_list_loops.cpp

package info (click to toggle)
boost1.42 1.42.0-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 277,864 kB
  • ctags: 401,076
  • sloc: cpp: 1,235,659; xml: 74,142; ansic: 41,313; python: 26,756; sh: 11,840; cs: 2,118; makefile: 655; perl: 494; yacc: 456; asm: 353; csh: 6
file content (118 lines) | stat: -rw-r--r-- 3,189 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// (C) Copyright Andrew Sutton 2009
//
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0 (See accompanying file
// LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)

#include <iostream>

#include <boost/assert.hpp>
#include <boost/graph/adjacency_list.hpp>

using namespace boost;

// TODO: Integrate this into a larger adj_list test suite.

template <typename Graph>
void test_graph_nonloop()
{
    typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
    typedef typename graph_traits<Graph>::edge_descriptor Edge;

    // Build a graph with 1 edge and turn it into a loop.
    Graph g(5);
    Vertex u = *vertices(g).first;
    Vertex v = *next(vertices(g).first, 2);
    add_edge(u, v, g);
    BOOST_ASSERT(num_vertices(g) == 5);
    BOOST_ASSERT(num_edges(g) == 1);
    remove_edge(u, v, g);
    BOOST_ASSERT(num_edges(g) == 0);

}


template <typename Graph>
void test_multigraph_nonloop()
{
    typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
    typedef typename graph_traits<Graph>::edge_descriptor Edge;

    // Build a graph with 1 edge and turn it into a loop.
    Graph g(5);
    Vertex u = *vertices(g).first;
    Vertex v = *next(vertices(g).first, 2);
    add_edge(u, v, g);
    add_edge(u, v, g);
    BOOST_ASSERT(num_vertices(g) == 5);
    BOOST_ASSERT(num_edges(g) == 2);
    remove_edge(u, v, g);
    BOOST_ASSERT(num_edges(g) == 0);

}

template <typename Graph>
void test_graph_loop()
{
    typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
    typedef typename graph_traits<Graph>::edge_descriptor Edge;

    Graph g(5);
    Vertex v = *next(vertices(g).first, 2);
    add_edge(v, v, g);
    BOOST_ASSERT(num_vertices(g) == 5);
    BOOST_ASSERT(num_edges(g) == 1);
    remove_edge(v, v, g);
    BOOST_ASSERT(num_edges(g) == 0);
}

template <typename Graph>
void test_multigraph_loop()
{
    typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
    typedef typename graph_traits<Graph>::edge_descriptor Edge;

    Graph g(5);
    Vertex v = *next(vertices(g).first, 2);
    add_edge(v, v, g);
    add_edge(v, v, g);
    BOOST_ASSERT(num_vertices(g) == 5);
    BOOST_ASSERT(num_edges(g) == 2);
    remove_edge(v, v, g);
    BOOST_ASSERT(num_edges(g) == 0);
}

template <typename Kind>
void test()
{
    typedef no_property na;
    typedef adjacency_list<vecS, vecS, Kind, na, na, na, listS> VVL;
    typedef adjacency_list<listS, vecS, Kind, na, na, na, listS> LVL;
    typedef adjacency_list<setS, vecS, Kind, na, na, na, listS> SVL;
    typedef adjacency_list<multisetS, vecS, Kind, na, na, na, listS> MVL;

    test_graph_nonloop<VVL>();
    test_graph_nonloop<LVL>();
    test_graph_nonloop<SVL>();
    test_graph_nonloop<MVL>();
    test_multigraph_nonloop<VVL>();
    test_multigraph_nonloop<LVL>();
    test_multigraph_nonloop<MVL>();
    test_graph_loop<VVL>();
    test_graph_loop<LVL>();
    test_graph_loop<SVL>();
    test_graph_loop<MVL>();
    test_multigraph_loop<VVL>();
    test_multigraph_loop<LVL>();
    test_multigraph_loop<MVL>();
}


int main()
{
    test<undirectedS>();
    test<directedS>();
    test<bidirectionalS>();

    return 0;
}