1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <boost/test/floating_point_comparison.hpp>
#include <boost/random.hpp>
template <typename float_type>
float_type randomize_float(void)
{
static boost::mt19937 rng;
static boost::uniform_real<float_type> dist(0.1, 1);
static boost::variate_generator<boost::mt19937&, boost::uniform_real<float_type> >
gen(rng, dist);
return gen();
}
template <typename float_type>
float_type randomize_float_slope(void)
{
static boost::mt19937 rng;
static boost::uniform_real<float_type> dist(0.0, 0.01);
static boost::variate_generator<boost::mt19937&, boost::uniform_real<float_type> >
gen(rng, dist);
return gen();
}
template <typename float_type>
void randomize_buffer(float_type * buffer, std::size_t size)
{
for (std::size_t i = 0; i != size; ++i)
buffer[i] = randomize_float<float_type>();
}
template <typename float_type>
void randomize_buffer(float_type * buffer, std::size_t size, float_type offset)
{
for (std::size_t i = 0; i != size; ++i)
buffer[i] = randomize_float<float_type>() + offset;
}
template <typename float_type>
void randomize_buffer(float_type * buffer, std::size_t size, float_type scale, float_type offset)
{
for (std::size_t i = 0; i != size; ++i)
buffer[i] = randomize_float<float_type>() * scale + offset;
}
template <typename float_type>
void compare_buffers(const float_type * ref, const float_type * test, std::size_t size, float difference = 2e-7)
{
for (std::size_t i = 0; i != size; ++i)
BOOST_REQUIRE_CLOSE_FRACTION( ref[i], test[i], difference );
}
template <typename float_type>
void compare_buffers_relative(const float_type * ref, const float_type * test, std::size_t size)
{
for (std::size_t i = 0; i != size; ++i)
BOOST_REQUIRE_CLOSE_FRACTION( ref[i], test[i], 1 );
}
|