hi_lo_ut.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <util/system/hi_lo.h>
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include "defaults.h"
  4. Y_UNIT_TEST_SUITE(HiLo) {
  5. Y_UNIT_TEST(HiLo32) {
  6. ui64 x = 0;
  7. Lo32(x) = 18;
  8. UNIT_ASSERT_VALUES_EQUAL(x, 18);
  9. Hi32(x) = 33;
  10. UNIT_ASSERT_VALUES_EQUAL(x, 141733920786);
  11. const ui64 y = 0x33c06196e94c03ab;
  12. UNIT_ASSERT_VALUES_EQUAL(Lo32(y).Get(), 0xe94c03ab);
  13. UNIT_ASSERT_VALUES_EQUAL(Hi32(y).Get(), 0x33c06196);
  14. }
  15. Y_UNIT_TEST(HiLo16) {
  16. ui32 x = 0;
  17. Lo16(x) = 18;
  18. UNIT_ASSERT_VALUES_EQUAL(x, 18);
  19. Hi16(x) = 33;
  20. UNIT_ASSERT_VALUES_EQUAL(x, 2162706);
  21. const ui32 y = 0xe94c03ab;
  22. UNIT_ASSERT_VALUES_EQUAL(Lo16(y).Get(), 0x03ab);
  23. UNIT_ASSERT_VALUES_EQUAL(Hi16(y).Get(), 0xe94c);
  24. }
  25. Y_UNIT_TEST(HiLo8) {
  26. ui16 x = 0;
  27. Lo8(x) = 18;
  28. UNIT_ASSERT_VALUES_EQUAL(x, 18);
  29. Hi8(x) = 33;
  30. UNIT_ASSERT_VALUES_EQUAL(x, 8466);
  31. const ui16 y = 0x03ab;
  32. UNIT_ASSERT_VALUES_EQUAL(Lo8(y).Get(), 0xab);
  33. UNIT_ASSERT_VALUES_EQUAL(Hi8(y).Get(), 0x03);
  34. }
  35. Y_UNIT_TEST(Combined) {
  36. ui32 x = 0;
  37. Lo8(Lo16(x)) = 18;
  38. UNIT_ASSERT_VALUES_EQUAL(x, 18);
  39. Hi8(Lo16(x)) = 33;
  40. UNIT_ASSERT_VALUES_EQUAL(x, 8466);
  41. const ui32 y = 0xe94c03ab;
  42. UNIT_ASSERT_VALUES_EQUAL(Lo8(Lo16(y)).Get(), 0xab);
  43. UNIT_ASSERT_VALUES_EQUAL(Hi8(Lo16(y)).Get(), 0x03);
  44. }
  45. Y_UNIT_TEST(NarrowFromWide) {
  46. const ui64 x = 0x1122334455667788ull;
  47. UNIT_ASSERT_VALUES_EQUAL(Lo8(x).Get(), 0x88);
  48. UNIT_ASSERT_VALUES_EQUAL(Hi8(x).Get(), 0x11);
  49. UNIT_ASSERT_VALUES_EQUAL(Lo16(x).Get(), 0x7788);
  50. UNIT_ASSERT_VALUES_EQUAL(Hi16(x).Get(), 0x1122);
  51. UNIT_ASSERT_VALUES_EQUAL(Lo32(x).Get(), 0x55667788);
  52. UNIT_ASSERT_VALUES_EQUAL(Hi32(x).Get(), 0x11223344);
  53. }
  54. } // Y_UNIT_TEST_SUITE(HiLo)