summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/graph/test/test_destruction.hpp
blob: 8cdfa1b67d7ada0f5c5c301422da44ae6e712948 (plain)
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
// (C) Copyright 2009 Andrew Sutton
//
// 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)

#ifndef TEST_DESTRUCTION_HPP
#define TEST_DESTRUCTION_HPP

#include <boost/concept/assert.hpp>
#include <utility>

/** @name Destroy Graph
 * Destroy the graph by removing vertices (if possible).
 */
//@{
// This will basically catch adjacency matrices, which don't get torn down.
template <typename Graph, typename VertexSet, typename Remove, typename Label>
void destroy_graph(Graph&, VertexSet const&, Remove, Label)
{ }

// This matches MutableGraph, so just remove a vertex and then clear.
template <typename Graph, typename VertexSet>
void destroy_graph(Graph& g, VertexSet const& verts, boost::mpl::true_, boost::mpl::false_) {
    using namespace boost;
    BOOST_CONCEPT_ASSERT((VertexListGraphConcept<Graph>));
    BOOST_CONCEPT_ASSERT((VertexMutableGraphConcept<Graph>));

    std::cout << "...destroy_normal\n";
    // Remove the roof vertex
    remove_vertex(verts[0], g);
    BOOST_ASSERT(num_vertices(g) == N - 1);
}

// This will match labeled graphs.
template <typename Graph, typename VertexSet>
void destroy_graph(Graph& g, VertexSet const&, boost::mpl::false_, boost::mpl::true_) {
    using namespace boost;
    BOOST_CONCEPT_ASSERT((VertexListGraphConcept<Graph>));
    // BOOST_CONCEPT_ASSERT(( VeretexMutableGraphConcept<Graph> ));

    std::cout << "...destroy_labeled\n";
    // Remove the roof vertex
    remove_vertex(0, g);
    BOOST_ASSERT(num_vertices(g) == N - 1);
}
//@}


/** @name Disconnect Graph
 * Disconnect edges in the graph. Note that this doesn't fully disconnect the
 * graph. It simply determines if we can disconnect an edge or two and verify
 * that the resulting graph is valid. The Labeled type parameter is used to
 * dispatch for unlabeled and labeled graphs.
 *
 * @todo This doesn't quite work for multigraphs...
 */
//@{

template <typename Graph, typename VertexSet>
void disconnect_graph(Graph& g, VertexSet const& verts, boost::mpl::false_) {
    using namespace boost;
    BOOST_CONCEPT_ASSERT((EdgeListGraphConcept<Graph>));
    BOOST_CONCEPT_ASSERT((EdgeMutableGraphConcept<Graph>));

    std::cout << "...disconnect_normal\n";
    typedef typename graph_traits<Graph>::edge_descriptor Edge;

    // Disconnect the "lollipop" from the house.
    Edge e = edge(verts[5], verts[3], g).first;
    remove_edge(e, g);
    BOOST_ASSERT(num_edges(g) == M - 1);

    // Remove the "floor" edge from the house.
    remove_edge(verts[3], verts[2], g);
    BOOST_ASSERT(num_edges(g) == M - 2);

    // Fully disconnect the roof vertex.
    clear_vertex(verts[0], g);
    BOOST_ASSERT(num_edges(g) == M - 4);

    // What happens if we try to remove an edge that doesn't exist?
    remove_edge(verts[5], verts[0], g);
    BOOST_ASSERT(num_edges(g) == M - 4);
}

template <typename Graph, typename VertexSet>
void disconnect_graph(Graph& g, VertexSet const&, boost::mpl::true_) {
    using namespace boost;
    BOOST_CONCEPT_ASSERT((EdgeListGraphConcept<Graph>));
    // BOOST_CONCEPT_ASSERT((EdgeMutableGraphConcept<Graph>));

    std::cout << "...disconnect_labeled\n";
    typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;

    // Disconnect the "lollipop" from the house.
    Edge e = boost::edge_by_label(5, 3, g).first;
    boost::remove_edge(e, g);
    BOOST_ASSERT(boost::num_edges(g) == M - 1);

    // Remove the "floor" edge from the house.
    boost::remove_edge_by_label(3, 2, g);
    BOOST_ASSERT(boost::num_edges(g) == M - 2);

    // Fully disconnect the roof vertex.
    clear_vertex_by_label(0, g);
    BOOST_ASSERT(boost::num_edges(g) == M - 4);

    // What happens if we try to remove an edge that doesn't exist?
    boost::remove_edge_by_label(5, 0, g);
    BOOST_ASSERT(boost::num_edges(g) == M - 4);
}
//@}

#endif