2012-05-19 09:46:38 +00:00
|
|
|
#ifndef SPROUT_LIBS_RANDOM_TEST_DISTRIBUTION_GENERIC_HPP
|
|
|
|
#define SPROUT_LIBS_RANDOM_TEST_DISTRIBUTION_GENERIC_HPP
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <sprout/random/linear_congruential.hpp>
|
|
|
|
#include <sprout/random/unique_seed.hpp>
|
|
|
|
#include <testspr/tools.hpp>
|
|
|
|
|
|
|
|
namespace testspr {
|
|
|
|
template<typename Distribution, typename Engine = sprout::random::minstd_rand0>
|
|
|
|
void random_distribution_test_generic() {
|
|
|
|
using namespace sprout;
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto parm = typename Distribution::param_type();
|
|
|
|
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto dist1 = Distribution(parm);
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto dist2 = Distribution(parm);
|
|
|
|
|
|
|
|
// min
|
|
|
|
// max
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(dist1.min() <= dist1.max());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// param
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(parm == dist1.param());
|
2011-12-23 11:59:33 +00:00
|
|
|
{
|
|
|
|
auto dist_temp = Distribution();
|
|
|
|
dist_temp.param(parm);
|
|
|
|
TESTSPR_ASSERT(dist_temp == dist1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// operator==
|
|
|
|
// operator!=
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(dist1 == dist2);
|
|
|
|
TESTSPR_BOTH_ASSERT(!(dist1 != dist2));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
std::string s;
|
|
|
|
|
|
|
|
// operator<<
|
|
|
|
{
|
|
|
|
std::ostringstream os;
|
|
|
|
os << dist1;
|
2013-10-05 09:10:47 +00:00
|
|
|
// ???
|
|
|
|
#if !defined(__clang__)
|
2013-10-02 06:44:33 +00:00
|
|
|
TESTSPR_ASSERT(!!os);
|
2013-10-05 09:10:47 +00:00
|
|
|
#endif
|
2011-12-23 11:59:33 +00:00
|
|
|
s = os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto dist_temp = Distribution();
|
|
|
|
|
|
|
|
// operator>>
|
|
|
|
{
|
|
|
|
std::istringstream is(s);
|
|
|
|
is >> dist_temp;
|
2013-10-05 09:10:47 +00:00
|
|
|
// ???
|
|
|
|
#if !defined(__clang__)
|
2013-10-02 06:44:33 +00:00
|
|
|
TESTSPR_ASSERT(!!is);
|
2013-10-05 09:10:47 +00:00
|
|
|
#endif
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TESTSPR_ASSERT(dist_temp == dist1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// operator()
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto eng = Engine(SPROUT_UNIQUE_SEED);
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto rnd = dist1(eng);
|
|
|
|
|
|
|
|
// result
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(dist1.min() <= rnd.result());
|
|
|
|
TESTSPR_BOTH_ASSERT(rnd.result() <= dist1.max());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// engine
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(rnd.engine().min() <= rnd.engine().max());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// distribution
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(rnd.distribution().min() <= rnd.distribution().max());
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace testspr
|
|
|
|
|
2012-05-19 09:46:38 +00:00
|
|
|
#endif // #ifndef SPROUT_LIBS_RANDOM_TEST_DISTRIBUTION_GENERIC_HPP
|