aboutsummaryrefslogtreecommitdiffstats
path: root/util/random
diff options
context:
space:
mode:
authornga <nga@yandex-team.ru>2022-02-10 16:48:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:09 +0300
commit1f553f46fb4f3c5eec631352cdd900a0709016af (patch)
treea231fba2c03b440becaea6c86a2702d0bfb0336e /util/random
parentc4de7efdedc25b49cbea74bd589eecb61b55b60a (diff)
downloadydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/random')
-rw-r--r--util/random/random.cpp12
-rw-r--r--util/random/random.h6
-rw-r--r--util/random/random_ut.cpp106
3 files changed, 62 insertions, 62 deletions
diff --git a/util/random/random.cpp b/util/random/random.cpp
index 71f9323856..a2191076b8 100644
--- a/util/random/random.cpp
+++ b/util/random/random.cpp
@@ -79,7 +79,7 @@ namespace {
return GetRndGen<TToRealType<TY>::TResult>()->Uniform(n); \
}
-DEF_RND(char)
+DEF_RND(char)
DEF_RND(unsigned char)
DEF_RND(unsigned int)
DEF_RND(unsigned long)
@@ -89,11 +89,11 @@ DEF_RND(unsigned long long)
#undef DEF_RND
template <>
-bool RandomNumber<bool>() {
- return RandomNumber<ui8>() % 2 == 0;
-}
-
-template <>
+bool RandomNumber<bool>() {
+ return RandomNumber<ui8>() % 2 == 0;
+}
+
+template <>
float RandomNumber<float>() {
float ret;
diff --git a/util/random/random.h b/util/random/random.h
index 16b52d3995..8e7e23bf87 100644
--- a/util/random/random.h
+++ b/util/random/random.h
@@ -5,7 +5,7 @@
*
* specialized for:
* all unsigned types (return value in range [0, MAX_VALUE_FOR_TYPE])
- * bool
+ * bool
* long double (return value in range [0, 1))
* double (return value in range [0, 1))
* float (return value in range [0, 1))
@@ -16,8 +16,8 @@ T RandomNumber();
/*
* returns value in range [0, max)
*/
-template <class T>
-T RandomNumber(T max);
+template <class T>
+T RandomNumber(T max);
/*
* Re-initialize random state - useful after forking in multi-process programs.
diff --git a/util/random/random_ut.cpp b/util/random/random_ut.cpp
index 30427676f3..c2ffc6ab27 100644
--- a/util/random/random_ut.cpp
+++ b/util/random/random_ut.cpp
@@ -1,9 +1,9 @@
#include "random.h"
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/generic/ylimits.h>
-
+
+#include <util/generic/ylimits.h>
+
template <class T>
static inline void AssertRange(T v, T r1, T r2) {
UNIT_ASSERT(v >= r1);
@@ -11,50 +11,50 @@ static inline void AssertRange(T v, T r1, T r2) {
}
Y_UNIT_TEST_SUITE(TRandomNumberTest) {
- template <typename T>
- void TestAll(T n) {
- for (T i = 0; i < n; ++i) {
- while (RandomNumber<T>(n) != i) {
- }
- }
- }
-
- template <typename T>
- void TestSome(T n) {
- for (int i = 0; i < 100; ++i) {
- UNIT_ASSERT(RandomNumber<T>(n) < n);
- }
- }
-
- template <typename T>
- void TestType() {
- TestAll<T>(1);
- TestAll<T>(2);
- TestAll<T>(3);
- TestAll<T>(4);
- TestAll<T>(5);
- TestAll<T>(6);
- TestAll<T>(9);
- TestAll<T>(15);
- TestAll<T>(16);
- TestSome<T>(Max<T>());
- TestSome<T>(Max<T>() - 1);
- TestSome<T>(Max<T>() - 2);
- TestSome<T>(Max<T>() - 3);
- TestSome<T>(Max<T>() - 4);
- TestSome<T>(Max<T>() - 5);
- TestSome<T>(Max<T>() - 7);
- TestSome<T>(Max<T>() - 8);
- TestSome<T>(Max<T>() - 2222);
- TestSome<T>(Max<T>() - 22222);
- }
-
+ template <typename T>
+ void TestAll(T n) {
+ for (T i = 0; i < n; ++i) {
+ while (RandomNumber<T>(n) != i) {
+ }
+ }
+ }
+
+ template <typename T>
+ void TestSome(T n) {
+ for (int i = 0; i < 100; ++i) {
+ UNIT_ASSERT(RandomNumber<T>(n) < n);
+ }
+ }
+
+ template <typename T>
+ void TestType() {
+ TestAll<T>(1);
+ TestAll<T>(2);
+ TestAll<T>(3);
+ TestAll<T>(4);
+ TestAll<T>(5);
+ TestAll<T>(6);
+ TestAll<T>(9);
+ TestAll<T>(15);
+ TestAll<T>(16);
+ TestSome<T>(Max<T>());
+ TestSome<T>(Max<T>() - 1);
+ TestSome<T>(Max<T>() - 2);
+ TestSome<T>(Max<T>() - 3);
+ TestSome<T>(Max<T>() - 4);
+ TestSome<T>(Max<T>() - 5);
+ TestSome<T>(Max<T>() - 7);
+ TestSome<T>(Max<T>() - 8);
+ TestSome<T>(Max<T>() - 2222);
+ TestSome<T>(Max<T>() - 22222);
+ }
+
Y_UNIT_TEST(TestWithLimit) {
- TestType<unsigned short>();
- TestType<unsigned int>();
- TestType<unsigned long>();
- TestType<unsigned long long>();
- }
+ TestType<unsigned short>();
+ TestType<unsigned int>();
+ TestType<unsigned long>();
+ TestType<unsigned long long>();
+ }
Y_UNIT_TEST(TestRandomNumberFloat) {
for (size_t i = 0; i < 1000; ++i) {
@@ -73,13 +73,13 @@ Y_UNIT_TEST_SUITE(TRandomNumberTest) {
AssertRange<long double>(RandomNumber<long double>(), 0.0, 1.0);
}
}
-
+
Y_UNIT_TEST(TestBoolean) {
- while (RandomNumber<bool>()) {
- }
- while (!RandomNumber<bool>()) {
- }
- }
+ while (RandomNumber<bool>()) {
+ }
+ while (!RandomNumber<bool>()) {
+ }
+ }
Y_UNIT_TEST(TestResetSeed) {
SetRandomSeed(42);
@@ -152,4 +152,4 @@ Y_UNIT_TEST_SUITE(TRandomNumberTest) {
UNIT_ASSERT_EQUAL(RandomNumber<ui32>(1 << 8), el);
}
}
-}
+}