@@ -26,6 +26,7 @@ void test_temp();
2626void test_bacon ();
2727void test_remove_labeled_vertex ();
2828void test_multiple_associative_container ();
29+ void test_remove_vertex_all_types ();
2930
3031int main ()
3132{
@@ -35,6 +36,7 @@ int main()
3536 test_bacon ();
3637 test_remove_labeled_vertex ();
3738 test_multiple_associative_container ();
39+ test_remove_vertex_all_types ();
3840}
3941
4042// ////////////////////////////////////
@@ -208,3 +210,210 @@ void test_multiple_associative_container()
208210 g.remove_vertex (" test" );
209211 BOOST_ASSERT (num_vertices (g) == 0 );
210212}
213+
214+ template <typename LabeledGraph, typename Label>
215+ void test_remove_vertex_suite (Label l1, Label l2, Label l3)
216+ {
217+ // remove + label cleanup
218+ {
219+ LabeledGraph g;
220+ g.add_vertex (l1);
221+ BOOST_ASSERT (num_vertices (g) == 1 );
222+ BOOST_ASSERT (g.vertex (l1) != LabeledGraph::null_vertex ());
223+
224+ g.remove_vertex (l1);
225+ BOOST_ASSERT (num_vertices (g) == 0 );
226+ BOOST_ASSERT (g.vertex (l1) == LabeledGraph::null_vertex ());
227+ }
228+
229+ // remove one + keep others
230+ {
231+ LabeledGraph g;
232+ g.add_vertex (l1);
233+ g.add_vertex (l2);
234+ g.add_vertex (l3);
235+ BOOST_ASSERT (num_vertices (g) == 3 );
236+
237+ g.remove_vertex (l2);
238+ BOOST_ASSERT (num_vertices (g) == 2 );
239+ BOOST_ASSERT (g.vertex (l2) == LabeledGraph::null_vertex ());
240+ BOOST_ASSERT (g.vertex (l1) != LabeledGraph::null_vertex ());
241+ BOOST_ASSERT (g.vertex (l3) != LabeledGraph::null_vertex ());
242+ }
243+
244+ // reuse label after removal
245+ {
246+ LabeledGraph g;
247+ g.add_vertex (l1);
248+ g.remove_vertex (l1);
249+ g.add_vertex (l1);
250+ BOOST_ASSERT (num_vertices (g) == 1 );
251+ BOOST_ASSERT (g.vertex (l1) != LabeledGraph::null_vertex ());
252+ }
253+
254+ // Remove all
255+ {
256+ LabeledGraph g;
257+ g.add_vertex (l1);
258+ g.add_vertex (l2);
259+ g.add_vertex (l3);
260+
261+ g.remove_vertex (l1);
262+ g.remove_vertex (l2);
263+ g.remove_vertex (l3);
264+ BOOST_ASSERT (num_vertices (g) == 0 );
265+ }
266+
267+ // Remove vertex with incident edges
268+ {
269+ LabeledGraph g;
270+ g.add_vertex (l1);
271+ g.add_vertex (l2);
272+ add_edge_by_label (l1, l2, g);
273+ BOOST_ASSERT (num_edges (g) == 1 );
274+
275+ g.remove_vertex (l1);
276+ BOOST_ASSERT (g.vertex (l1) == LabeledGraph::null_vertex ());
277+ BOOST_ASSERT (num_edges (g) == 0 );
278+ }
279+ }
280+
281+ template <typename Graph, typename LabeledGraph, typename Label>
282+ void test_remove_vertex_suite_ptr_variant (Label l1, Label l2, Label l3)
283+ {
284+ // remove + label cleanup
285+ {
286+ Graph graph;
287+ LabeledGraph g (&graph);
288+ g.add_vertex (l1);
289+ BOOST_ASSERT (num_vertices (g) == 1 );
290+ BOOST_ASSERT (g.vertex (l1) != LabeledGraph::null_vertex ());
291+
292+ g.remove_vertex (l1);
293+ BOOST_ASSERT (num_vertices (g) == 0 );
294+ BOOST_ASSERT (g.vertex (l1) == LabeledGraph::null_vertex ());
295+ }
296+
297+ // remove one + keep others
298+ {
299+ Graph graph;
300+ LabeledGraph g (&graph);
301+ g.add_vertex (l1);
302+ g.add_vertex (l2);
303+ g.add_vertex (l3);
304+ BOOST_ASSERT (num_vertices (g) == 3 );
305+
306+ g.remove_vertex (l2);
307+ BOOST_ASSERT (num_vertices (g) == 2 );
308+ BOOST_ASSERT (g.vertex (l2) == LabeledGraph::null_vertex ());
309+ BOOST_ASSERT (g.vertex (l1) != LabeledGraph::null_vertex ());
310+ BOOST_ASSERT (g.vertex (l3) != LabeledGraph::null_vertex ());
311+ }
312+
313+ // reuse label after removal
314+ {
315+ Graph graph;
316+ LabeledGraph g (&graph);
317+ g.add_vertex (l1);
318+ g.remove_vertex (l1);
319+ g.add_vertex (l1);
320+ BOOST_ASSERT (num_vertices (g) == 1 );
321+ BOOST_ASSERT (g.vertex (l1) != LabeledGraph::null_vertex ());
322+ }
323+
324+ // Remove all
325+ {
326+ Graph graph;
327+ LabeledGraph g (&graph);
328+ g.add_vertex (l1);
329+ g.add_vertex (l2);
330+ g.add_vertex (l3);
331+
332+ g.remove_vertex (l1);
333+ g.remove_vertex (l2);
334+ g.remove_vertex (l3);
335+ BOOST_ASSERT (num_vertices (g) == 0 );
336+ }
337+
338+ // Remove vertex with incident edges
339+ {
340+ Graph graph;
341+ LabeledGraph g (&graph);
342+ g.add_vertex (l1);
343+ g.add_vertex (l2);
344+ add_edge_by_label (l1, l2, g);
345+ BOOST_ASSERT (num_edges (g) == 1 );
346+
347+ g.remove_vertex (l1);
348+ BOOST_ASSERT (g.vertex (l1) == LabeledGraph::null_vertex ());
349+ BOOST_ASSERT (num_edges (g) == 0 );
350+ }
351+ }
352+
353+ void test_remove_vertex_all_types ()
354+ {
355+ // defaultS
356+ test_remove_vertex_suite<
357+ labeled_graph<directed_graph<>, string>
358+ >(" a" , " b" , " c" );
359+
360+ test_remove_vertex_suite<
361+ labeled_graph<undirected_graph<>, string>
362+ >(" a" , " b" , " c" );
363+
364+ // mapS
365+ test_remove_vertex_suite<
366+ labeled_graph<directed_graph<>, string, mapS>
367+ >(" a" , " b" , " c" );
368+
369+ test_remove_vertex_suite<
370+ labeled_graph<undirected_graph<>, string, mapS>
371+ >(" a" , " b" , " c" );
372+
373+ // hash_mapS
374+ test_remove_vertex_suite<
375+ labeled_graph<directed_graph<>, string, hash_mapS>
376+ >(" a" , " b" , " c" );
377+
378+ test_remove_vertex_suite<
379+ labeled_graph<undirected_graph<>, string, hash_mapS>
380+ >(" a" , " b" , " c" );
381+
382+ // adjacency_list + vecS not supported (unstable removal would require remapping the map)
383+
384+ // adjacency_list + listS (stable removal)
385+ test_remove_vertex_suite<
386+ labeled_graph<adjacency_list<listS, listS, directedS>, string, mapS>
387+ >(" a" , " b" , " c" );
388+
389+ test_remove_vertex_suite<
390+ labeled_graph<adjacency_list<listS, listS, undirectedS>, string, mapS>
391+ >(" a" , " b" , " c" );
392+
393+ // unsigned labels (vecS)
394+ test_remove_vertex_suite<
395+ labeled_graph<adjacency_list<listS, listS, directedS>, unsigned , vecS>
396+ >(0u , 1u , 2u );
397+
398+ // Pointer specialization, string labels
399+ test_remove_vertex_suite_ptr_variant<
400+ directed_graph<>,
401+ labeled_graph<directed_graph<>*, string>
402+ >(" a" , " b" , " c" );
403+
404+ test_remove_vertex_suite_ptr_variant<
405+ undirected_graph<>,
406+ labeled_graph<undirected_graph<>*, string>
407+ >(" a" , " b" , " c" );
408+
409+ test_remove_vertex_suite_ptr_variant<
410+ directed_graph<>,
411+ labeled_graph<directed_graph<>*, string, hash_mapS>
412+ >(" a" , " b" , " c" );
413+
414+ // Pointer specialization, unsigned labels
415+ test_remove_vertex_suite_ptr_variant<
416+ adjacency_list<listS, listS, directedS>,
417+ labeled_graph<adjacency_list<listS, listS, directedS>*, unsigned , vecS>
418+ >(0u , 1u , 2u );
419+ }
0 commit comments