unordered/test/helpers/generators.hpp
Daniel James b1ba0f65c8 Merged revisions 42856-42881 via svnmerge from
https://svn.boost.org/svn/boost/branches/unordered/trunk

........
  r42880 | danieljames | 2008-01-20 16:10:43 +0000 (Sun, 20 Jan 2008) | 17 lines
  
  Simplify the tests a little:
  
  Add a parameter to random_values to control what sort of values it generates.
  This means that instead of using equivalent_object to test collisions (which
  was a total hack) we now just need another parameter.
  
  This requires some meta programming to act differently for maps and sets.
  Because of this pairs no longer need to be generated so remove the code for
  doing that (which doesn't work on some compilers).
  
  Remove the generator object, just call generate directly.
  
  Remove some of the tests using int containers, they didn't really add to
  anthing other than the compile time (some tests are timing out).
........


[SVN r42882]
2008-01-20 18:55:57 +00:00

71 lines
1.6 KiB
C++

// Copyright 2005-2007 Daniel James.
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// This uses std::rand to generate random values for tests.
// Which is not good as different platforms will be running different tests.
// It would be much better to use Boost.Random, but it doesn't
// support all the compilers that I want to test on.
#if !defined(BOOST_UNORDERED_TEST_HELPERS_GENERATORS_HEADER)
#define BOOST_UNORDERED_TEST_HELPERS_GENERATORS_HEADER
#include <string>
#include <utility>
#include <stdexcept>
#include <cstdlib>
#include <boost/type_traits/add_const.hpp>
#include "./fwd.hpp"
namespace test
{
struct seed_t {
seed_t(unsigned int x) {
using namespace std;
srand(x);
}
};
inline int generate(int const*)
{
using namespace std;
return rand();
}
inline char generate(char const*)
{
using namespace std;
return static_cast<char>((rand() >> 1) % (128-32) + 32);
}
inline signed char generate(signed char const*)
{
using namespace std;
return static_cast<signed char>(rand());
}
inline std::string generate(std::string const*)
{
using namespace std;
char* char_ptr = 0;
std::string result;
int length = rand() % 10;
for(int i = 0; i < length; ++i)
result += generate(char_ptr);
return result;
}
float generate(float const*)
{
using namespace std;
return (float) rand() / (float) RAND_MAX;
}
}
#endif