aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/ymath_ut.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/generic/ymath_ut.cpp
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/ymath_ut.cpp')
-rw-r--r--util/generic/ymath_ut.cpp220
1 files changed, 110 insertions, 110 deletions
diff --git a/util/generic/ymath_ut.cpp b/util/generic/ymath_ut.cpp
index 29190b55eb..934137b056 100644
--- a/util/generic/ymath_ut.cpp
+++ b/util/generic/ymath_ut.cpp
@@ -1,132 +1,132 @@
#include "bitops.h"
-#include "ymath.h"
-
+#include "ymath.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <util/stream/output.h>
-#include <util/datetime/cputimer.h>
-
-#include <limits>
-
-template <class T>
+#include <util/datetime/cputimer.h>
+
+#include <limits>
+
+template <class T>
static inline T SlowClp2(T t) noexcept {
Y_ASSERT(t > 0);
-
+
T ret = 1;
-
+
while (ret < t) {
ret *= 2;
- }
-
+ }
+
return ret;
-}
-
-class TMathTest: public TTestBase {
- UNIT_TEST_SUITE(TMathTest);
- UNIT_TEST(TestClp2)
- UNIT_TEST(TestClpSimple)
- UNIT_TEST(TestSqr)
- UNIT_TEST(TestLog2)
- UNIT_TEST(ValueBitCount)
- UNIT_TEST(TestErf);
- UNIT_TEST(TestLogGamma);
- UNIT_TEST(TestIsValidFloat);
+}
+
+class TMathTest: public TTestBase {
+ UNIT_TEST_SUITE(TMathTest);
+ UNIT_TEST(TestClp2)
+ UNIT_TEST(TestClpSimple)
+ UNIT_TEST(TestSqr)
+ UNIT_TEST(TestLog2)
+ UNIT_TEST(ValueBitCount)
+ UNIT_TEST(TestErf);
+ UNIT_TEST(TestLogGamma);
+ UNIT_TEST(TestIsValidFloat);
UNIT_TEST(TestAbs);
UNIT_TEST(TestPower);
UNIT_TEST(TestSigmoid);
UNIT_TEST(TestCeilDiv);
- UNIT_TEST_SUITE_END();
-
-private:
- void TestClp2();
- void TestSqr();
- void TestErf();
- void TestLogGamma();
+ UNIT_TEST_SUITE_END();
+
+private:
+ void TestClp2();
+ void TestSqr();
+ void TestErf();
+ void TestLogGamma();
void TestAbs();
void TestPower();
void TestSigmoid();
void TestCeilDiv();
-
- inline void TestIsValidFloat() {
- UNIT_ASSERT(IsValidFloat(-Max<double>() / 2.));
- }
-
- inline void TestClpSimple() {
- UNIT_ASSERT_EQUAL(FastClp2<ui32>(12), 16);
- UNIT_ASSERT_EQUAL(FastClp2<ui16>(11), 16);
- UNIT_ASSERT_EQUAL(FastClp2<ui8>(10), 16);
-
- UNIT_ASSERT_EQUAL(FastClp2<ui32>(15), 16);
- UNIT_ASSERT_EQUAL(FastClp2<ui32>(16), 16);
- UNIT_ASSERT_EQUAL(FastClp2<ui32>(17), 32);
- }
-
- inline void TestLog2() {
- UNIT_ASSERT_DOUBLES_EQUAL(Log2(2.0), 1.0, 1e-10);
+
+ inline void TestIsValidFloat() {
+ UNIT_ASSERT(IsValidFloat(-Max<double>() / 2.));
+ }
+
+ inline void TestClpSimple() {
+ UNIT_ASSERT_EQUAL(FastClp2<ui32>(12), 16);
+ UNIT_ASSERT_EQUAL(FastClp2<ui16>(11), 16);
+ UNIT_ASSERT_EQUAL(FastClp2<ui8>(10), 16);
+
+ UNIT_ASSERT_EQUAL(FastClp2<ui32>(15), 16);
+ UNIT_ASSERT_EQUAL(FastClp2<ui32>(16), 16);
+ UNIT_ASSERT_EQUAL(FastClp2<ui32>(17), 32);
+ }
+
+ inline void TestLog2() {
+ UNIT_ASSERT_DOUBLES_EQUAL(Log2(2.0), 1.0, 1e-10);
UNIT_ASSERT_DOUBLES_EQUAL(Log2(2ull), 1.0, 1e-10);
UNIT_ASSERT_DOUBLES_EQUAL(Log2(2.0f), 1.0f, 1e-7f);
- }
-
- inline void ValueBitCount() {
- UNIT_ASSERT_VALUES_EQUAL(GetValueBitCount(1), 1u);
- UNIT_ASSERT_VALUES_EQUAL(GetValueBitCount(2), 2u);
- UNIT_ASSERT_VALUES_EQUAL(GetValueBitCount(3), 2u);
- UNIT_ASSERT_VALUES_EQUAL(GetValueBitCount(257), 9u);
- }
-};
-
-UNIT_TEST_SUITE_REGISTRATION(TMathTest);
-
-void TMathTest::TestSqr() {
- UNIT_ASSERT_EQUAL(Sqr(2), 4);
- UNIT_ASSERT_EQUAL(Sqr(2.0), 4.0);
-}
-
-void TMathTest::TestClp2() {
+ }
+
+ inline void ValueBitCount() {
+ UNIT_ASSERT_VALUES_EQUAL(GetValueBitCount(1), 1u);
+ UNIT_ASSERT_VALUES_EQUAL(GetValueBitCount(2), 2u);
+ UNIT_ASSERT_VALUES_EQUAL(GetValueBitCount(3), 2u);
+ UNIT_ASSERT_VALUES_EQUAL(GetValueBitCount(257), 9u);
+ }
+};
+
+UNIT_TEST_SUITE_REGISTRATION(TMathTest);
+
+void TMathTest::TestSqr() {
+ UNIT_ASSERT_EQUAL(Sqr(2), 4);
+ UNIT_ASSERT_EQUAL(Sqr(2.0), 4.0);
+}
+
+void TMathTest::TestClp2() {
for (ui8 i = 1; i < 127; ++i) {
- UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
- }
-
+ UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
+ }
+
for (ui16 i = 1; i < 255; ++i) {
- UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
- }
-
+ UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
+ }
+
for (ui32 i = 1; i < 255; ++i) {
- UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
- }
-
+ UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
+ }
+
for (ui64 i = 1; i < 255; ++i) {
- UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
- }
-
- if (0) {
- {
- TFuncTimer timer("fast");
- size_t ret = 0;
-
- for (size_t i = 0; i < 10000000; ++i) {
- ret += FastClp2(i);
- }
-
- Cerr << ret << Endl;
- }
-
- {
- TFuncTimer timer("slow");
- size_t ret = 0;
-
- for (size_t i = 0; i < 10000000; ++i) {
- ret += SlowClp2(i);
- }
-
- Cerr << ret << Endl;
- }
- }
-}
+ UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
+ }
+
+ if (0) {
+ {
+ TFuncTimer timer("fast");
+ size_t ret = 0;
+
+ for (size_t i = 0; i < 10000000; ++i) {
+ ret += FastClp2(i);
+ }
+
+ Cerr << ret << Endl;
+ }
+
+ {
+ TFuncTimer timer("slow");
+ size_t ret = 0;
+
+ for (size_t i = 0; i < 10000000; ++i) {
+ ret += SlowClp2(i);
+ }
+
+ Cerr << ret << Endl;
+ }
+ }
+}
void TMathTest::TestErf() {
static const double a = -5.0;
- static const double b = 5.0;
+ static const double b = 5.0;
static const int n = 50;
static const double step = (b - a) / n;
@@ -136,12 +136,12 @@ void TMathTest::TestErf() {
-0.9999779, -0.9999250, -0.9997640, -0.9993115, -0.9981372,
-0.9953223, -0.9890905, -0.9763484, -0.9522851, -0.9103140,
-0.8427008, -0.7421010, -0.6038561, -0.4283924, -0.2227026,
- 0.0000000,
- 0.2227026, 0.4283924, 0.6038561, 0.7421010, 0.8427008,
- 0.9103140, 0.9522851, 0.9763484, 0.9890905, 0.9953223,
- 0.9981372, 0.9993115, 0.9997640, 0.9999250, 0.9999779,
- 0.9999940, 0.9999985, 0.9999996, 0.9999999, 1.0000000,
- 1.0000000, 1.0000000, 1.0000000, 1.0000000, 1.0000000};
+ 0.0000000,
+ 0.2227026, 0.4283924, 0.6038561, 0.7421010, 0.8427008,
+ 0.9103140, 0.9522851, 0.9763484, 0.9890905, 0.9953223,
+ 0.9981372, 0.9993115, 0.9997640, 0.9999250, 0.9999779,
+ 0.9999940, 0.9999985, 0.9999996, 0.9999999, 1.0000000,
+ 1.0000000, 1.0000000, 1.0000000, 1.0000000, 1.0000000};
double x = a;
for (int i = 0; i <= n; ++i, x += step) {
@@ -154,7 +154,7 @@ void TMathTest::TestLogGamma() {
double curVal = 0.0;
for (int i = 1; i <= 20; i++) {
curVal += log((double)i);
- UNIT_ASSERT_DOUBLES_EQUAL(curVal, LogGamma((double)(i + 1)), 1e-6);
+ UNIT_ASSERT_DOUBLES_EQUAL(curVal, LogGamma((double)(i + 1)), 1e-6);
}
curVal = log(M_PI) / 2.0;
for (int i = 1; i <= 20; i++) {