diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/random/common_ops_ut.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/random/common_ops_ut.cpp')
-rw-r--r-- | util/random/common_ops_ut.cpp | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/util/random/common_ops_ut.cpp b/util/random/common_ops_ut.cpp index 905912bd1e..3610b5d2ff 100644 --- a/util/random/common_ops_ut.cpp +++ b/util/random/common_ops_ut.cpp @@ -1,69 +1,69 @@ -#include "common_ops.h" -#include "random.h" - +#include "common_ops.h" +#include "random.h" + #include <library/cpp/testing/unittest/registar.h> - -#include <util/digest/numeric.h> - -#include <random> - + +#include <util/digest/numeric.h> + +#include <random> + Y_UNIT_TEST_SUITE(TestCommonRNG) { - template <class T> - struct TRng: public TCommonRNG<T, TRng<T>> { + template <class T> + struct TRng: public TCommonRNG<T, TRng<T>> { inline T GenRand() noexcept { - return IntHash(C_++); - } - - T C_ = RandomNumber<T>(); - }; - + return IntHash(C_++); + } + + T C_ = RandomNumber<T>(); + }; + Y_UNIT_TEST(TestUniform1) { - TRng<ui32> r; - - for (size_t i = 0; i < 1000; ++i) { - UNIT_ASSERT(r.Uniform(10) < 10); - } - } - + TRng<ui32> r; + + for (size_t i = 0; i < 1000; ++i) { + UNIT_ASSERT(r.Uniform(10) < 10); + } + } + Y_UNIT_TEST(TestUniform2) { - TRng<ui32> r; - - for (size_t i = 0; i < 1000; ++i) { - UNIT_ASSERT(r.Uniform(1) == 0); - } - } - + TRng<ui32> r; + + for (size_t i = 0; i < 1000; ++i) { + UNIT_ASSERT(r.Uniform(1) == 0); + } + } + Y_UNIT_TEST(TestUniform3) { - TRng<ui32> r; - - for (size_t i = 0; i < 1000; ++i) { - auto x = r.Uniform(100, 200); - - UNIT_ASSERT(x >= 100); - UNIT_ASSERT(x < 200); - } - } - + TRng<ui32> 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<ui32> r; - r.C_ = 17; - std::normal_distribution<float> nd(0, 1); - UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.877167, 0.01); - } - - { - TRng<ui64> r; - r.C_ = 17; - std::normal_distribution<double> nd(0, 1); - UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.5615566731, 0.01); - } - - { - TRng<ui16> r; - r.C_ = 17; - std::normal_distribution<long double> nd(0, 1); - UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.430375088, 0.01); - } - } -} + { + TRng<ui32> r; + r.C_ = 17; + std::normal_distribution<float> nd(0, 1); + UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.877167, 0.01); + } + + { + TRng<ui64> r; + r.C_ = 17; + std::normal_distribution<double> nd(0, 1); + UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.5615566731, 0.01); + } + + { + TRng<ui16> r; + r.C_ = 17; + std::normal_distribution<long double> nd(0, 1); + UNIT_ASSERT_DOUBLES_EQUAL(nd(r), -0.430375088, 0.01); + } + } +} |