OKlibrary  0.2.1.6
Tests_Generators.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 8.9.2003 (Swansea)
00002 /* Copyright 2003 - 2007 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00008 #ifndef TESTSGENERATORSWAECHTER
00009 
00010 #define TESTSGENERATORSWAECHTER
00011 
00012 #include <cassert>
00013 
00014 #include <boost/graph/graph_traits.hpp>
00015 #include <boost/graph/graph_concepts.hpp>
00016 
00017 #include <boost/concept_check.hpp>
00018 #include <boost/type_traits.hpp>
00019 
00020 #include "Generators.hpp"
00021 #include "Support.hpp"
00022 
00023 namespace Tests_Generators {
00024 
00025   template<typename Graph>
00026   void complete_graph(typename boost::graph_traits<Graph>::vertices_size_type max_size) {
00027 
00028     boost::function_requires<boost::EdgeListGraphConcept<Graph> >();
00029 
00030     typedef typename boost::graph_traits<Graph>::vertices_size_type vertices_size_type;
00031     {
00032       Graph g(Generators::complete_graph<Graph>(0));
00033       assert(boost::num_vertices(g) == 0);
00034       assert(boost::num_edges(g) == 0);
00035       g = Generators::complete_graph<Graph>(1);
00036       assert(boost::num_vertices(g) == 1);
00037       assert(boost::num_edges(g) == 0);
00038     }
00039     for (vertices_size_type n = 2; n <= max_size; ++n) {
00040       Graph g(Generators::complete_graph<Graph>(n));
00041       assert(boost::num_vertices(g) == n);
00042       typedef typename boost::graph_traits<Graph>::directed_category directed_category;
00043       if (boost::is_same<directed_category, boost::directed_tag>::value)
00044   assert(boost::num_edges(g) == n * (n-1));
00045       else if (boost::is_same<directed_category, boost::undirected_tag>::value)
00046   assert(boost::num_edges(g) == (n * (n-1))/2);
00047       else {
00048   // THROW XXXXXXXXXXXXXXXXXXXXXX
00049       }
00050       typedef typename boost::graph_traits<Graph>::vertex_iterator vertex_iterator;
00051       typedef typename boost::graph_traits<Graph>::edge_iterator edge_iterator;
00052       const std::pair<vertex_iterator, vertex_iterator> pvi = boost::vertices(g);
00053       const std::pair<edge_iterator, edge_iterator> pei = boost::edges(g);
00054       for (vertex_iterator i = pvi.first; i != pvi.second; ++i)
00055   for (vertex_iterator j = ++vertex_iterator(i); j != pvi.second; ++j)
00056     if (boost::is_same<directed_category, boost::directed_tag>::value) {
00057       assert(std::find_if(pei.first, pei.second, Support::edge_checker(g, *i, *j)) != pei.second);
00058       assert(std::find_if(pei.first, pei.second, Support::edge_checker(g, *j, *i)) != pei.second);
00059     }
00060     else
00061       assert(std::find_if(pei.first, pei.second, Support::edge_checker(g, *i, *j)) != pei.second);
00062     }
00063   }
00064 }
00065 
00066 
00067 #endif