File: test_graphs.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 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 (208 lines) | stat: -rw-r--r-- 9,255 bytes parent folder | download | duplicates (10)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// (C) Copyright 2009-2010 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)

#include <iostream>
#include "typestr.hpp"

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_matrix.hpp>
#include <boost/graph/undirected_graph.hpp>
#include <boost/graph/directed_graph.hpp>
#include <boost/graph/compressed_sparse_row_graph.hpp>
#include <boost/graph/labeled_graph.hpp>
#include <boost/graph/subgraph.hpp>

#include "test_graph.hpp"

// This test module is a testing ground to determine if graphs and graph
// adaptors actually implement the graph concepts correctly.

using namespace boost;

int main()
{
    // Bootstrap all of the tests by declaring a kind graph and  asserting some
    // basic properties about it.
    {
        typedef undirected_graph< VertexBundle, EdgeBundle, GraphBundle > Graph;
        BOOST_META_ASSERT(is_undirected_graph< Graph >);
        BOOST_META_ASSERT(is_multigraph< Graph >);
        BOOST_META_ASSERT(is_incidence_graph< Graph >);
        BOOST_META_ASSERT(is_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(has_vertex_property< Graph >);
        BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(has_edge_property< Graph >);
        BOOST_META_ASSERT(has_bundled_edge_property< Graph >);
        BOOST_META_ASSERT(is_mutable_graph< Graph >);
        BOOST_META_ASSERT(is_mutable_property_graph< Graph >);
        Graph g;
        test_graph(g);
    }
    {
        typedef directed_graph< VertexBundle, EdgeBundle, GraphBundle > Graph;
        BOOST_META_ASSERT(is_directed_graph< Graph >);
        BOOST_META_ASSERT(is_multigraph< Graph >);
        BOOST_META_ASSERT(is_incidence_graph< Graph >);
        BOOST_META_ASSERT(is_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(is_directed_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(has_vertex_property< Graph >);
        BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(has_edge_property< Graph >);
        BOOST_META_ASSERT(has_bundled_edge_property< Graph >);
        BOOST_META_ASSERT(is_mutable_graph< Graph >);
        BOOST_META_ASSERT(is_mutable_property_graph< Graph >);
        Graph g;
        test_graph(g);
    }
    {
        typedef adjacency_list< vecS, vecS, undirectedS, VertexBundle,
            EdgeBundle, GraphBundle >
            Graph;
        BOOST_META_ASSERT(is_undirected_graph< Graph >);
        BOOST_META_ASSERT(is_multigraph< Graph >);
        BOOST_META_ASSERT(is_incidence_graph< Graph >);
        BOOST_META_ASSERT(is_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(has_vertex_property< Graph >);
        BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(has_edge_property< Graph >);
        BOOST_META_ASSERT(has_bundled_edge_property< Graph >);
        BOOST_META_ASSERT(is_add_only_property_graph< Graph >);
        Graph g;
        test_graph(g);
    }
    {
        typedef adjacency_list< vecS, vecS, directedS, VertexBundle, EdgeBundle,
            GraphBundle >
            Graph;
        Graph g;
        BOOST_META_ASSERT(is_directed_graph< Graph >);
        BOOST_META_ASSERT(is_multigraph< Graph >);
        BOOST_META_ASSERT(is_incidence_graph< Graph >);
        BOOST_META_ASSERT(!is_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(is_directed_unidirectional_graph< Graph >);
        BOOST_META_ASSERT(has_vertex_property< Graph >);
        BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(has_edge_property< Graph >);
        BOOST_META_ASSERT(has_bundled_edge_property< Graph >);
        BOOST_META_ASSERT(is_add_only_property_graph< Graph >);
        test_graph(g);
    }
    {
        // Common bidi adjlist
        typedef adjacency_list< vecS, vecS, bidirectionalS, VertexBundle,
            EdgeBundle, GraphBundle >
            Graph;
        BOOST_META_ASSERT(is_directed_graph< Graph >);
        BOOST_META_ASSERT(is_multigraph< Graph >);
        BOOST_META_ASSERT(is_incidence_graph< Graph >);
        BOOST_META_ASSERT(is_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(is_directed_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(has_vertex_property< Graph >);
        BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(has_edge_property< Graph >);
        BOOST_META_ASSERT(has_bundled_edge_property< Graph >);
        BOOST_META_ASSERT(is_add_only_property_graph< Graph >);
        Graph g;
        test_graph(g);
    }
    {
        // Same as above, but testing VL==listS
        typedef adjacency_list< vecS, listS, bidirectionalS, VertexBundle,
            EdgeBundle, GraphBundle >
            Graph;
        BOOST_META_ASSERT(is_directed_graph< Graph >);
        BOOST_META_ASSERT(is_multigraph< Graph >);
        BOOST_META_ASSERT(is_incidence_graph< Graph >);
        BOOST_META_ASSERT(is_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(is_directed_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(has_vertex_property< Graph >);
        BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(has_edge_property< Graph >);
        BOOST_META_ASSERT(has_bundled_edge_property< Graph >);
        BOOST_META_ASSERT(is_mutable_property_graph< Graph >);
        Graph g;
        test_graph(g);
    }
    {
        typedef adjacency_matrix< directedS, VertexBundle, EdgeBundle,
            GraphBundle >
            Graph;
        BOOST_META_ASSERT(is_directed_graph< Graph >);
        BOOST_META_ASSERT(!is_multigraph< Graph >);
        BOOST_META_ASSERT(has_vertex_property< Graph >);
        BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(has_edge_property< Graph >);
        BOOST_META_ASSERT(has_bundled_edge_property< Graph >);
        BOOST_META_ASSERT(is_mutable_edge_graph< Graph >);
        BOOST_META_ASSERT(is_mutable_edge_property_graph< Graph >);
        Graph g(N);
        test_graph(g);
    }
    {
        typedef adjacency_matrix< directedS, VertexBundle, EdgeBundle > Graph;
        BOOST_META_ASSERT(is_directed_graph< Graph >);
        BOOST_META_ASSERT(!is_multigraph< Graph >);
        BOOST_META_ASSERT(has_vertex_property< Graph >);
        BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(has_edge_property< Graph >);
        BOOST_META_ASSERT(has_bundled_edge_property< Graph >);
        BOOST_META_ASSERT(is_mutable_edge_graph< Graph >);
        BOOST_META_ASSERT(is_mutable_edge_property_graph< Graph >);
        Graph g(N);
        test_graph(g);
    }
    {
        typedef labeled_graph< directed_graph<>, unsigned > Graph;
        BOOST_META_ASSERT(is_directed_graph< Graph >);
        BOOST_META_ASSERT(is_multigraph< Graph >);
        BOOST_META_ASSERT(is_incidence_graph< Graph >);
        BOOST_META_ASSERT(is_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(is_directed_bidirectional_graph< Graph >);
        BOOST_META_ASSERT(is_labeled_mutable_property_graph< Graph >);
        BOOST_META_ASSERT(is_labeled_graph< Graph >);
        BOOST_META_ASSERT(!has_vertex_property< Graph >);
        BOOST_META_ASSERT(!has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(!has_edge_property< Graph >);
        BOOST_META_ASSERT(!has_bundled_edge_property< Graph >);
        BOOST_META_ASSERT(is_labeled_mutable_graph< Graph >);
        Graph g;
        test_graph(g);
    }

    // FIXME: CSR doesn't have mutability traits so we can't generalize the
    // constructions of the required graph. Just assert the properties for now.
    // NOTE: CSR graphs are also atypical in that they don't have "normal"
    // vertex and edge properties. They're "abnormal" in the sense that they
    // have a valid bundled type, but the property types are no_property.
    {
        typedef compressed_sparse_row_graph< directedS, VertexBundle,
            EdgeBundle, GraphBundle >
            Graph;
        BOOST_META_ASSERT(is_directed_graph< Graph >);
        BOOST_META_ASSERT(is_multigraph< Graph >);
        BOOST_META_ASSERT(has_graph_property< Graph >);
        BOOST_META_ASSERT(has_bundled_graph_property< Graph >);
        BOOST_META_ASSERT(!has_vertex_property< Graph >);
        BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(!has_edge_property< Graph >);
        BOOST_META_ASSERT(has_bundled_edge_property< Graph >);
    }
    {
        typedef compressed_sparse_row_graph< bidirectionalS, VertexBundle,
            EdgeBundle, GraphBundle >
            Graph;
        BOOST_META_ASSERT(is_directed_graph< Graph >);
        BOOST_META_ASSERT(is_multigraph< Graph >);
        BOOST_META_ASSERT(has_graph_property< Graph >);
        BOOST_META_ASSERT(has_bundled_graph_property< Graph >);
        BOOST_META_ASSERT(!has_vertex_property< Graph >);
        BOOST_META_ASSERT(has_bundled_vertex_property< Graph >);
        BOOST_META_ASSERT(!has_edge_property< Graph >);
        BOOST_META_ASSERT(has_bundled_edge_property< Graph >);
    }

    // TODO: What other kinds of graphs do we have here...
}