big_integer_ut.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "big_integer.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <util/system/byteorder.h>
  4. #include <util/stream/str.h>
  5. Y_UNIT_TEST_SUITE(BigInteger) {
  6. using NOpenSsl::TBigInteger;
  7. Y_UNIT_TEST(Initialization) {
  8. constexpr ui64 testVal = 12345678900;
  9. const auto fromULong = TBigInteger::FromULong(testVal);
  10. const ui64 testArea = HostToInet(testVal); // transform to big-endian
  11. const auto fromRegion = TBigInteger::FromRegion(&testArea, sizeof(testArea));
  12. UNIT_ASSERT(fromULong == fromRegion);
  13. UNIT_ASSERT_VALUES_EQUAL(fromULong, fromRegion);
  14. const auto fromULongOther = TBigInteger::FromULong(22345678900);
  15. UNIT_ASSERT(fromULong != fromULongOther);
  16. }
  17. Y_UNIT_TEST(Decimal) {
  18. UNIT_ASSERT_VALUES_EQUAL(TBigInteger::FromULong(123456789).ToDecimalString(), "123456789");
  19. }
  20. Y_UNIT_TEST(Region) {
  21. const auto v1 = TBigInteger::FromULong(1234567890);
  22. char buf[1024];
  23. const auto v2 = TBigInteger::FromRegion(buf, v1.ToRegion(buf));
  24. UNIT_ASSERT_VALUES_EQUAL(v1, v2);
  25. }
  26. Y_UNIT_TEST(Output) {
  27. TStringStream ss;
  28. ss << TBigInteger::FromULong(123456789);
  29. UNIT_ASSERT_VALUES_EQUAL(ss.Str(), "123456789");
  30. }
  31. }