aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/int128/ut/int128_ut.cpp
diff options
context:
space:
mode:
authorVlad Yaroslavlev <vladon@vladon.com>2022-02-10 16:46:25 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:25 +0300
commit344ea37b4a345701ab0e67de2266a1c1bd7baf2d (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /library/cpp/int128/ut/int128_ut.cpp
parent706b83ed7de5a473436620367af31fc0ceecde07 (diff)
downloadydb-344ea37b4a345701ab0e67de2266a1c1bd7baf2d.tar.gz
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/int128/ut/int128_ut.cpp')
-rw-r--r--library/cpp/int128/ut/int128_ut.cpp104
1 files changed, 52 insertions, 52 deletions
diff --git a/library/cpp/int128/ut/int128_ut.cpp b/library/cpp/int128/ut/int128_ut.cpp
index 0d68e42100..7339264017 100644
--- a/library/cpp/int128/ut/int128_ut.cpp
+++ b/library/cpp/int128/ut/int128_ut.cpp
@@ -1,56 +1,56 @@
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <library/cpp/int128/int128.h>
-
-#include <util/generic/cast.h>
-
-#include <type_traits>
-
-Y_UNIT_TEST_SUITE(Uint128Suite) {
- Y_UNIT_TEST(Uint128DefaultCtor) {
- const ui128 value{};
- UNIT_ASSERT_EQUAL(GetLow(value), 0);
- UNIT_ASSERT_EQUAL(GetHigh(value), 0);
- }
-
- Y_UNIT_TEST(Uint128NumericLimits) {
- UNIT_ASSERT_EQUAL(std::numeric_limits<ui128>::digits, 128);
- UNIT_ASSERT_EQUAL(std::numeric_limits<ui128>::max() + 1, ui128{0});
- }
-
- Y_UNIT_TEST(Uint128Sizeof) {
- UNIT_ASSERT_EQUAL(sizeof(ui128), sizeof(ui64) * 2);
- }
-
- Y_UNIT_TEST(Uint128Cast) {
- // see util/generic/cast.h
- const auto underlyingTypeIsSelf = std::is_same<::NPrivate::TUnderlyingTypeOrSelf<ui128>, ui128>::value;
- UNIT_ASSERT_EQUAL(underlyingTypeIsSelf, true);
-
- const auto convertibleUi128Ui128 = ::NPrivate::TSafelyConvertible<ui128, ui128>::Result;
- const auto convertibleUi64Ui128 = ::NPrivate::TSafelyConvertible<ui64, ui128>::Result;
- const auto convertibleUi128Ui64 = ::NPrivate::TSafelyConvertible<ui128, ui64>::Result;
- UNIT_ASSERT_EQUAL(convertibleUi128Ui128, true); // from ui128 to ui128 => safe
- UNIT_ASSERT_EQUAL(convertibleUi64Ui128, false); // from ui128 to ui64 => not safe
- UNIT_ASSERT_EQUAL(convertibleUi128Ui64, true); // from ui64 to ui128 => safe
- }
-
- Y_UNIT_TEST(SafeIntegerCastTest) {
- ui128 narrowNumber = 1;
-
- UNIT_ASSERT_NO_EXCEPTION(SafeIntegerCast<ui64>(narrowNumber));
-
- ui128 wideNumber{0};
- wideNumber -= 1;
- UNIT_ASSERT_EXCEPTION(SafeIntegerCast<ui64>(wideNumber), yexception);
- }
-
- Y_UNIT_TEST(SignbitTest) {
- UNIT_ASSERT(!std::signbit(ui128{0}));
- UNIT_ASSERT(!std::signbit(ui128{-1}));
- UNIT_ASSERT(!std::signbit(i128{0}));
- UNIT_ASSERT(std::signbit(i128{-1}));
- }
+
+#include <util/generic/cast.h>
+
+#include <type_traits>
+
+Y_UNIT_TEST_SUITE(Uint128Suite) {
+ Y_UNIT_TEST(Uint128DefaultCtor) {
+ const ui128 value{};
+ UNIT_ASSERT_EQUAL(GetLow(value), 0);
+ UNIT_ASSERT_EQUAL(GetHigh(value), 0);
+ }
+
+ Y_UNIT_TEST(Uint128NumericLimits) {
+ UNIT_ASSERT_EQUAL(std::numeric_limits<ui128>::digits, 128);
+ UNIT_ASSERT_EQUAL(std::numeric_limits<ui128>::max() + 1, ui128{0});
+ }
+
+ Y_UNIT_TEST(Uint128Sizeof) {
+ UNIT_ASSERT_EQUAL(sizeof(ui128), sizeof(ui64) * 2);
+ }
+
+ Y_UNIT_TEST(Uint128Cast) {
+ // see util/generic/cast.h
+ const auto underlyingTypeIsSelf = std::is_same<::NPrivate::TUnderlyingTypeOrSelf<ui128>, ui128>::value;
+ UNIT_ASSERT_EQUAL(underlyingTypeIsSelf, true);
+
+ const auto convertibleUi128Ui128 = ::NPrivate::TSafelyConvertible<ui128, ui128>::Result;
+ const auto convertibleUi64Ui128 = ::NPrivate::TSafelyConvertible<ui64, ui128>::Result;
+ const auto convertibleUi128Ui64 = ::NPrivate::TSafelyConvertible<ui128, ui64>::Result;
+ UNIT_ASSERT_EQUAL(convertibleUi128Ui128, true); // from ui128 to ui128 => safe
+ UNIT_ASSERT_EQUAL(convertibleUi64Ui128, false); // from ui128 to ui64 => not safe
+ UNIT_ASSERT_EQUAL(convertibleUi128Ui64, true); // from ui64 to ui128 => safe
+ }
+
+ Y_UNIT_TEST(SafeIntegerCastTest) {
+ ui128 narrowNumber = 1;
+
+ UNIT_ASSERT_NO_EXCEPTION(SafeIntegerCast<ui64>(narrowNumber));
+
+ ui128 wideNumber{0};
+ wideNumber -= 1;
+ UNIT_ASSERT_EXCEPTION(SafeIntegerCast<ui64>(wideNumber), yexception);
+ }
+
+ Y_UNIT_TEST(SignbitTest) {
+ UNIT_ASSERT(!std::signbit(ui128{0}));
+ UNIT_ASSERT(!std::signbit(ui128{-1}));
+ UNIT_ASSERT(!std::signbit(i128{0}));
+ UNIT_ASSERT(std::signbit(i128{-1}));
+ }
Y_UNIT_TEST(ToStringTest) {
// int128
@@ -80,4 +80,4 @@ Y_UNIT_TEST_SUITE(Uint128Suite) {
),
"235108557486403940296800289353599800327");
}
-}
+}