sl@0
|
1 |
//=======================================================================
|
sl@0
|
2 |
// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
|
sl@0
|
3 |
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
|
sl@0
|
4 |
//
|
sl@0
|
5 |
// Distributed under the Boost Software License, Version 1.0. (See
|
sl@0
|
6 |
// accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
7 |
// http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
8 |
//=======================================================================
|
sl@0
|
9 |
|
sl@0
|
10 |
/*
|
sl@0
|
11 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
sl@0
|
12 |
*/
|
sl@0
|
13 |
|
sl@0
|
14 |
#include <boost/config.hpp>
|
sl@0
|
15 |
#include <iostream>
|
sl@0
|
16 |
#include <vector>
|
sl@0
|
17 |
#include <utility>
|
sl@0
|
18 |
#include <algorithm>
|
sl@0
|
19 |
#include <boost/graph/adjacency_list.hpp>
|
sl@0
|
20 |
|
sl@0
|
21 |
#ifdef __SYMBIAN32__
|
sl@0
|
22 |
#include "std_log_result.h"
|
sl@0
|
23 |
#define LOG_FILENAME_LINE __FILE__, __LINE__
|
sl@0
|
24 |
#endif
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
|
sl@0
|
28 |
using namespace boost;
|
sl@0
|
29 |
using namespace std;
|
sl@0
|
30 |
|
sl@0
|
31 |
typedef property<vertex_color_t, default_color_type,
|
sl@0
|
32 |
property<vertex_distance_t,int,
|
sl@0
|
33 |
property<vertex_degree_t,int,
|
sl@0
|
34 |
property<vertex_in_degree_t, int,
|
sl@0
|
35 |
property<vertex_out_degree_t,int> > > > > VertexProperty;
|
sl@0
|
36 |
typedef property<edge_weight_t,int> EdgeProperty;
|
sl@0
|
37 |
typedef adjacency_list<vecS, vecS, bidirectionalS,
|
sl@0
|
38 |
VertexProperty, EdgeProperty> Graph;
|
sl@0
|
39 |
|
sl@0
|
40 |
template <class Graph>
|
sl@0
|
41 |
void print(Graph& g) {
|
sl@0
|
42 |
typename Graph::vertex_iterator i, end;
|
sl@0
|
43 |
typename Graph::out_edge_iterator ei, edge_end;
|
sl@0
|
44 |
for(boost::tie(i,end) = vertices(g); i != end; ++i) {
|
sl@0
|
45 |
cout << *i << " --> ";
|
sl@0
|
46 |
for (boost::tie(ei,edge_end) = out_edges(*i, g); ei != edge_end; ++ei)
|
sl@0
|
47 |
cout << target(*ei, g) << " ";
|
sl@0
|
48 |
cout << endl;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
std::size_t myrand(std::size_t N) {
|
sl@0
|
53 |
std::size_t ret = rand() % N;
|
sl@0
|
54 |
// cout << "N = " << N << " rand = " << ret << endl;
|
sl@0
|
55 |
return ret;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
template <class Graph>
|
sl@0
|
59 |
bool check_edge(Graph& g, std::size_t a, std::size_t b) {
|
sl@0
|
60 |
typedef typename Graph::vertex_descriptor Vertex;
|
sl@0
|
61 |
typename Graph::adjacency_iterator vi, viend, found;
|
sl@0
|
62 |
boost::tie(vi, viend) = adjacent_vertices(vertex(a,g), g);
|
sl@0
|
63 |
|
sl@0
|
64 |
found = find(vi, viend, vertex(b, g));
|
sl@0
|
65 |
if ( found == viend )
|
sl@0
|
66 |
return false;
|
sl@0
|
67 |
|
sl@0
|
68 |
return true;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
int main(int, char*[])
|
sl@0
|
72 |
{
|
sl@0
|
73 |
std::size_t N = 5;
|
sl@0
|
74 |
|
sl@0
|
75 |
Graph g(N);
|
sl@0
|
76 |
int i;
|
sl@0
|
77 |
|
sl@0
|
78 |
bool is_failed = false;
|
sl@0
|
79 |
|
sl@0
|
80 |
for (i=0; i<6; ++i) {
|
sl@0
|
81 |
std::size_t a = myrand(N), b = myrand(N);
|
sl@0
|
82 |
while ( a == b ) b = myrand(N);
|
sl@0
|
83 |
cout << "edge edge (" << a << "," << b <<")" << endl;
|
sl@0
|
84 |
//add edges
|
sl@0
|
85 |
add_edge(a, b, g);
|
sl@0
|
86 |
is_failed = is_failed || (! check_edge(g, a, b) );
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
if ( is_failed )
|
sl@0
|
90 |
cerr << " Failed."<< endl;
|
sl@0
|
91 |
else
|
sl@0
|
92 |
cerr << " Passed."<< endl;
|
sl@0
|
93 |
|
sl@0
|
94 |
print(g);
|
sl@0
|
95 |
|
sl@0
|
96 |
//remove_edge
|
sl@0
|
97 |
for (i = 0; i<2; ++i) {
|
sl@0
|
98 |
std::size_t a = myrand(N), b = myrand(N);
|
sl@0
|
99 |
while ( a == b ) b = myrand(N);
|
sl@0
|
100 |
cout << "remove edge (" << a << "," << b <<")" << endl;
|
sl@0
|
101 |
remove_edge(a, b, g);
|
sl@0
|
102 |
is_failed = is_failed || check_edge(g, a, b);
|
sl@0
|
103 |
}
|
sl@0
|
104 |
if ( is_failed )
|
sl@0
|
105 |
cerr << " Failed."<< endl;
|
sl@0
|
106 |
else
|
sl@0
|
107 |
cerr << " Passed."<< endl;
|
sl@0
|
108 |
|
sl@0
|
109 |
print(g);
|
sl@0
|
110 |
|
sl@0
|
111 |
//add_vertex
|
sl@0
|
112 |
is_failed = false;
|
sl@0
|
113 |
std::size_t old_N = N;
|
sl@0
|
114 |
std::size_t vid = add_vertex(g);
|
sl@0
|
115 |
std::size_t vidp1 = add_vertex(g);
|
sl@0
|
116 |
|
sl@0
|
117 |
N = num_vertices(g);
|
sl@0
|
118 |
if ( (N - 2) != old_N )
|
sl@0
|
119 |
cerr << " Failed."<< endl;
|
sl@0
|
120 |
else
|
sl@0
|
121 |
cerr << " Passed."<< endl;
|
sl@0
|
122 |
|
sl@0
|
123 |
is_failed = false;
|
sl@0
|
124 |
for (i=0; i<2; ++i) {
|
sl@0
|
125 |
std::size_t a = myrand(N), b = myrand(N);
|
sl@0
|
126 |
while ( a == vid ) a = myrand(N);
|
sl@0
|
127 |
while ( b == vidp1 ) b = myrand(N);
|
sl@0
|
128 |
cout << "add edge (" << vid << "," << a <<")" << endl;
|
sl@0
|
129 |
cout << "add edge (" << vid << "," << vidp1 <<")" << endl;
|
sl@0
|
130 |
add_edge(vid, a, g);
|
sl@0
|
131 |
add_edge(b, vidp1, g);
|
sl@0
|
132 |
is_failed = is_failed || ! check_edge(g, vid, a);
|
sl@0
|
133 |
is_failed = is_failed || ! check_edge(g, b, vidp1);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
if ( is_failed )
|
sl@0
|
136 |
cerr << " Failed."<< endl;
|
sl@0
|
137 |
else
|
sl@0
|
138 |
cerr << " Passed."<< endl;
|
sl@0
|
139 |
print(g);
|
sl@0
|
140 |
|
sl@0
|
141 |
// clear_vertex
|
sl@0
|
142 |
std::size_t c = myrand(N);
|
sl@0
|
143 |
is_failed = false;
|
sl@0
|
144 |
clear_vertex(c, g);
|
sl@0
|
145 |
|
sl@0
|
146 |
if ( out_degree(c, g) != 0 )
|
sl@0
|
147 |
is_failed = true;
|
sl@0
|
148 |
|
sl@0
|
149 |
cout << "Removing vertex " << c << endl;
|
sl@0
|
150 |
remove_vertex(c, g);
|
sl@0
|
151 |
|
sl@0
|
152 |
old_N = N;
|
sl@0
|
153 |
N = num_vertices(g);
|
sl@0
|
154 |
|
sl@0
|
155 |
if ( (N + 1) != old_N )
|
sl@0
|
156 |
is_failed = true;
|
sl@0
|
157 |
|
sl@0
|
158 |
if ( is_failed )
|
sl@0
|
159 |
cerr << " Failed."<< endl;
|
sl@0
|
160 |
else
|
sl@0
|
161 |
cerr << " Passed."<< endl;
|
sl@0
|
162 |
|
sl@0
|
163 |
print(g);
|
sl@0
|
164 |
|
sl@0
|
165 |
#ifdef __SYMBIAN32__
|
sl@0
|
166 |
|
sl@0
|
167 |
std_log(LOG_FILENAME_LINE,"[End Test Case ]");
|
sl@0
|
168 |
testResultXml("graph");
|
sl@0
|
169 |
close_log_file();
|
sl@0
|
170 |
#endif
|
sl@0
|
171 |
return 0;
|
sl@0
|
172 |
}
|