#include "common_ops.h" #include "random.h" #include #include #include Y_UNIT_TEST_SUITE(TestCommonRNG) { template struct TRng: public TCommonRNG> { inline T GenRand() noexcept { return IntHash(C_++); } T C_ = RandomNumber(); }; Y_UNIT_TEST(TestUniform1) { TRng r; for (size_t i = 0; i < 1000; ++i) { UNIT_ASSERT(r.Uniform(10) < 10); } } Y_UNIT_TEST(TestUniform2) { TRng r; for (size_t i = 0; i < 1000; ++i) { UNIT_ASSERT(r.Uniform(1) == 0); } } Y_UNIT_TEST(TestUniform3) { TRng r; for (size_t i = 0; i < 1000; ++i) { auto x = r.Uniform(100, 200); UNIT_ASSERT(x >= 100); UNIT_ASSERT(x < 200); } } Y_UNIT_TEST(TestStlCompatibility) { { TRng r; r.C_ = 17; std::normal_distribution nd(0, 1); UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.877167, 0.01); } { TRng r; r.C_ = 17; std::normal_distribution nd(0, 1); UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.5615566731, 0.01); } { TRng r; r.C_ = 17; std::normal_distribution nd(0, 1); UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.430375088, 0.01); } } }