2012-05-19 09:46:38 +00:00
|
|
|
#ifndef SPROUT_LIBS_RANDOM_TEST_ENGINE_GENERIC_HPP
|
|
|
|
#define SPROUT_LIBS_RANDOM_TEST_ENGINE_GENERIC_HPP
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <sprout/random/unique_seed.hpp>
|
|
|
|
#include <testspr/tools.hpp>
|
|
|
|
|
|
|
|
namespace testspr {
|
|
|
|
template<typename Engine>
|
|
|
|
void random_engine_test_generic() {
|
|
|
|
using namespace sprout;
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto eng1 = Engine(SPROUT_UNIQUE_SEED);
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto eng2 = Engine(SPROUT_UNIQUE_SEED);
|
|
|
|
|
|
|
|
// min
|
|
|
|
// max
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(eng1.min() <= eng1.max());
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
// operator==
|
|
|
|
// operator!=
|
2013-07-26 08:01:10 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(eng1 == eng1);
|
|
|
|
TESTSPR_BOTH_ASSERT(!(eng1 == eng2));
|
|
|
|
TESTSPR_BOTH_ASSERT(eng1 != eng2);
|
|
|
|
TESTSPR_BOTH_ASSERT(!(eng1 != eng1));
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
std::string s;
|
|
|
|
|
|
|
|
// operator<<
|
|
|
|
{
|
|
|
|
std::ostringstream os;
|
|
|
|
os << eng1;
|
2013-10-02 06:44:33 +00:00
|
|
|
TESTSPR_ASSERT(!!os);
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
s = os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto eng_temp = Engine();
|
|
|
|
|
|
|
|
// operator>>
|
|
|
|
{
|
|
|
|
std::istringstream is(s);
|
|
|
|
is >> eng_temp;
|
2013-10-02 06:44:33 +00:00
|
|
|
TESTSPR_ASSERT(!!is);
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//TESTSPR_ASSERT(eng_temp == eng1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// operator()
|
|
|
|
{
|
|
|
|
SPROUT_STATIC_CONSTEXPR auto rnd = eng1();
|
|
|
|
|
|
|
|
// result
|
2012-06-15 15:08:42 +00:00
|
|
|
TESTSPR_BOTH_ASSERT(eng1.min() <= rnd.result());
|
|
|
|
TESTSPR_BOTH_ASSERT(rnd.result() <= eng1.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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace testspr
|
|
|
|
|
2012-05-19 09:46:38 +00:00
|
|
|
#endif // #ifndef SPROUT_LIBS_RANDOM_TEST_ENGINE_GENERIC_HPP
|