2006-05-17 17:19:16 +00:00
|
|
|
|
2009-03-09 20:56:23 +00:00
|
|
|
// Copyright 2005-2009 Daniel James.
|
2006-07-01 22:31:26 +00:00
|
|
|
// 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)
|
2006-05-17 17:19:16 +00:00
|
|
|
|
2007-05-01 21:24:48 +00:00
|
|
|
// 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.
|
2006-05-17 17:19:16 +00:00
|
|
|
|
|
|
|
|
#if !defined(BOOST_UNORDERED_TEST_HELPERS_GENERATORS_HEADER)
|
|
|
|
|
#define BOOST_UNORDERED_TEST_HELPERS_GENERATORS_HEADER
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <utility>
|
2006-10-31 22:19:26 +00:00
|
|
|
#include <stdexcept>
|
2007-05-01 21:24:48 +00:00
|
|
|
#include <cstdlib>
|
2008-01-10 22:30:46 +00:00
|
|
|
#include <boost/type_traits/add_const.hpp>
|
2006-05-17 17:19:16 +00:00
|
|
|
#include "./fwd.hpp"
|
|
|
|
|
|
|
|
|
|
namespace test
|
|
|
|
|
{
|
2007-12-06 11:42:28 +00:00
|
|
|
struct seed_t {
|
|
|
|
|
seed_t(unsigned int x) {
|
|
|
|
|
using namespace std;
|
|
|
|
|
srand(x);
|
|
|
|
|
}
|
|
|
|
|
};
|
2006-05-17 17:19:16 +00:00
|
|
|
|
|
|
|
|
inline int generate(int const*)
|
|
|
|
|
{
|
2007-05-01 21:24:48 +00:00
|
|
|
using namespace std;
|
|
|
|
|
return rand();
|
2006-05-17 17:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline char generate(char const*)
|
|
|
|
|
{
|
2007-05-01 21:24:48 +00:00
|
|
|
using namespace std;
|
Merged revisions 41808-41821,41823-41927,41934-41942,41944-41950,41952-41993,41998-42091,42094-42095,42104-42105,42107,42109,42111-42152,42154,42160-42171,42173-42180,42183-42196,42198-42402 via svnmerge from
2008-01-01 20:21:04 +00:00
|
|
|
return static_cast<char>((rand() >> 1) % (128-32) + 32);
|
2006-05-17 17:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-17 23:17:21 +00:00
|
|
|
inline signed char generate(signed char const*)
|
|
|
|
|
{
|
|
|
|
|
using namespace std;
|
2007-08-14 09:55:30 +00:00
|
|
|
return static_cast<signed char>(rand());
|
2007-07-17 23:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-17 17:19:16 +00:00
|
|
|
inline std::string generate(std::string const*)
|
|
|
|
|
{
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2008-01-20 18:55:57 +00:00
|
|
|
char* char_ptr = 0;
|
2006-05-17 17:19:16 +00:00
|
|
|
|
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
|
|
int length = rand() % 10;
|
|
|
|
|
for(int i = 0; i < length; ++i)
|
2008-01-20 18:55:57 +00:00
|
|
|
result += generate(char_ptr);
|
2006-05-17 17:19:16 +00:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float generate(float const*)
|
|
|
|
|
{
|
2008-01-08 18:15:01 +00:00
|
|
|
using namespace std;
|
2007-05-01 21:24:48 +00:00
|
|
|
return (float) rand() / (float) RAND_MAX;
|
2006-05-17 17:19:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|