File: adj_list_loops.cpp

package info (click to toggle)
boost1.83 1.83.0-4.2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 545,456 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (105 lines) | stat: -rw-r--r-- 2,989 bytes parent folder | download | duplicates (13)
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
// (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;

    // 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;

    // 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;

    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;

    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;
}