Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52916 - trunk/libs/graph/test
From: asutton_at_[hidden]
Date: 2009-05-11 13:43:49


Author: asutton
Date: 2009-05-11 13:43:48 EDT (Mon, 11 May 2009)
New Revision: 52916
URL: http://svn.boost.org/trac/boost/changeset/52916

Log:
Added missing test file
Added:
   trunk/libs/graph/test/labeled_graph.cpp (contents, props changed)

Added: trunk/libs/graph/test/labeled_graph.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/graph/test/labeled_graph.cpp 2009-05-11 13:43:48 EDT (Mon, 11 May 2009)
@@ -0,0 +1,147 @@
+// (C) Copyright 2007-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)
+
+#include <iostream>
+#include <string>
+#include <set>
+
+#define BOOST_NO_HASH
+
+#include <boost/assert.hpp>
+#include <boost/range.hpp>
+
+#include <boost/graph/undirected_graph.hpp>
+#include <boost/graph/directed_graph.hpp>
+#include <boost/graph/labeled_graph.hpp>
+
+#include "typestr.hpp"
+
+using std::cout;
+using std::string;
+using namespace boost;
+
+void test_norm();
+void test_temp();
+void test_bacon();
+
+int main() {
+ test_norm();
+ test_temp();
+ test_bacon();
+}
+
+//////////////////////////////////////
+// Utility Functions and Types
+//////////////////////////////////////
+
+
+struct Actor {
+ Actor() { }
+ Actor(string const& s) : name(s) { }
+ string name;
+};
+
+struct Movie {
+ Movie() { }
+ Movie(string const& s) : name(s) { }
+ string name;
+};
+
+
+template <typename Graph>
+void init_graph(Graph& g) {
+ for(int i = 0; i < 6; ++i) {
+ add_vertex(i, g);
+ }
+}
+
+template <typename Graph>
+void label_graph(Graph& g)
+{
+ typedef typename graph_traits<Graph>::vertex_iterator Iter;
+ Iter f, l;
+ int x = 0;
+ for(tie(f, l) = vertices(g); f != l; ++f, ++x) {
+ label_vertex(*f, x, g);
+ }
+}
+
+template <typename Graph>
+void build_graph(Graph& g) {
+ // This is the graph shown on the wikipedia page for Graph Theory.
+ add_edge(5, 3, g);
+ add_edge(3, 4, g);
+ add_edge(3, 2, g);
+ add_edge(4, 1, g);
+ add_edge(4, 0, g);
+ add_edge(2, 1, g);
+ add_edge(1, 0, g);
+ BOOST_ASSERT(num_vertices(g) == 6);
+ BOOST_ASSERT(num_edges(g) == 7);
+}
+
+//////////////////////////////////////
+// Temporal Labelings
+//////////////////////////////////////
+
+void test_norm() {
+ {
+ typedef labeled_graph<undirected_graph<>, unsigned> Graph;
+ Graph g;
+ init_graph(g);
+ build_graph(g);
+ }
+
+ {
+ typedef labeled_graph<directed_graph<>, unsigned> Graph;
+ Graph g;
+ init_graph(g);
+ build_graph(g);
+ }
+}
+
+//////////////////////////////////////
+// Temporal Labelings
+//////////////////////////////////////
+
+
+void test_temp() {
+ typedef undirected_graph<> Graph;
+ typedef labeled_graph<Graph*, int> LabGraph;
+ Graph g(6);
+ LabGraph lg(&g);
+ label_graph(lg);
+ build_graph(lg);
+}
+
+//////////////////////////////////////
+// Labeled w/ Properties
+//////////////////////////////////////
+
+void test_bacon() {
+ // More banal tests that use different properties.
+ {
+ string bacon = "Kevin Bacon";
+ string slater = "Christian Slater";
+
+ typedef labeled_graph<undirected_graph<Actor, Movie>, string> Graph;
+ Graph g;
+ add_vertex(bacon, g);
+ add_vertex(slater, g);
+ add_edge(bacon, slater, Movie("Murder in the First"), g);
+ }
+
+ {
+ string bacon = "Kevin Bacon";
+ string slater = "Christian Slater";
+
+ typedef labeled_graph<directed_graph<Actor, Movie>, string> Graph;
+ Graph g;
+ add_vertex(bacon, g);
+ add_vertex(slater, g);
+ add_edge(bacon, slater, Movie("Murder in the First"), g);
+ }
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk