diff options
author | akhropov <akhropov@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
commit | 298c6da79f1d8f35089a67f463f0b541bec36d9b (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/generic/ymath_ut.cpp | |
parent | 00afc96e9c0298054b7386fa7fb9e3cc3d67b974 (diff) | |
download | ydb-298c6da79f1d8f35089a67f463f0b541bec36d9b.tar.gz |
Restoring authorship annotation for <akhropov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic/ymath_ut.cpp')
-rw-r--r-- | util/generic/ymath_ut.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/util/generic/ymath_ut.cpp b/util/generic/ymath_ut.cpp index 15514e4bb3..29190b55eb 100644 --- a/util/generic/ymath_ut.cpp +++ b/util/generic/ymath_ut.cpp @@ -34,7 +34,7 @@ class TMathTest: public TTestBase { UNIT_TEST(TestAbs); UNIT_TEST(TestPower); UNIT_TEST(TestSigmoid); - UNIT_TEST(TestCeilDiv); + UNIT_TEST(TestCeilDiv); UNIT_TEST_SUITE_END(); private: @@ -45,7 +45,7 @@ private: void TestAbs(); void TestPower(); void TestSigmoid(); - void TestCeilDiv(); + void TestCeilDiv(); inline void TestIsValidFloat() { UNIT_ASSERT(IsValidFloat(-Max<double>() / 2.)); @@ -191,30 +191,30 @@ void TMathTest::TestSigmoid() { UNIT_ASSERT_EQUAL(Sigmoid(-5000.), 0.0); UNIT_ASSERT_EQUAL(Sigmoid(5000.), 1.0); } - -void TMathTest::TestCeilDiv() { - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(2, 3), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(3, 3), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui32>(12, 2), 6); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui64>(10, 3), 4); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui64>(0, 10), 0); - - // negative numbers - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(0, -10), 0); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-1, 2), 0); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-1, -2), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(10, -5), -2); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-3, -4), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-6, -4), 2); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-6, 4), -1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-13, 4), -3); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-14, -4), 4); - - // check values close to overflow - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(255, 10), 26); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui32>(std::numeric_limits<ui32>::max() - 3, std::numeric_limits<ui32>::max()), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i32>(std::numeric_limits<i32>::max() - 3, std::numeric_limits<i32>::max()), 1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i32>(std::numeric_limits<i32>::min(), std::numeric_limits<i32>::max()), -1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i8>(std::numeric_limits<i8>::max(), std::numeric_limits<i8>::min() + 1), -1); - UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i64>(std::numeric_limits<i64>::max() - 2, -(std::numeric_limits<i64>::min() + 1)), 1); -} + +void TMathTest::TestCeilDiv() { + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(2, 3), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(3, 3), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui32>(12, 2), 6); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui64>(10, 3), 4); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui64>(0, 10), 0); + + // negative numbers + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(0, -10), 0); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-1, 2), 0); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-1, -2), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(10, -5), -2); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-3, -4), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-6, -4), 2); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-6, 4), -1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-13, 4), -3); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv(-14, -4), 4); + + // check values close to overflow + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui8>(255, 10), 26); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<ui32>(std::numeric_limits<ui32>::max() - 3, std::numeric_limits<ui32>::max()), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i32>(std::numeric_limits<i32>::max() - 3, std::numeric_limits<i32>::max()), 1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i32>(std::numeric_limits<i32>::min(), std::numeric_limits<i32>::max()), -1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i8>(std::numeric_limits<i8>::max(), std::numeric_limits<i8>::min() + 1), -1); + UNIT_ASSERT_VALUES_EQUAL(CeilDiv<i64>(std::numeric_limits<i64>::max() - 2, -(std::numeric_limits<i64>::min() + 1)), 1); +} |