guid_ut.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <library/cpp/testing/gtest/gtest.h>
  2. #include <library/cpp/yt/misc/guid.h>
  3. #include <util/generic//algorithm.h>
  4. namespace NYT {
  5. namespace {
  6. ////////////////////////////////////////////////////////////////////////////////
  7. TEST(TGuidTest, CreateRandom)
  8. {
  9. auto guid = TGuid::Create();
  10. auto otherGuid = TGuid::Create();
  11. EXPECT_FALSE(guid == otherGuid);
  12. }
  13. TEST(TGuidTest, FormattableGuid)
  14. {
  15. EXPECT_EQ(TFormattableGuid(TGuid::FromString("1-2-3-4")).ToStringBuf(), "1-2-3-4");
  16. EXPECT_EQ(TFormattableGuid(TGuid::FromString("abcd-ef12-dcba-4321")).ToStringBuf(), "abcd-ef12-dcba-4321");
  17. }
  18. TEST(TGuidTest, StarshipOperator)
  19. {
  20. std::vector<TGuid> guids{
  21. TGuid::FromString("abcd-ef12-dcba-4321"),
  22. TGuid::FromString("1-2-3-4"),
  23. TGuid::FromString("1-2-3-4"),
  24. TGuid::FromString("bada-13aa-abab-ffff"),
  25. };
  26. Sort(guids);
  27. for (int index = 0; index < std::ssize(guids) - 1; index++) {
  28. auto first = guids[index];
  29. auto second = guids[index];
  30. if (first == second) {
  31. EXPECT_EQ(first <=> second, std::strong_ordering::equal);
  32. } else {
  33. EXPECT_EQ(first <=> second, std::strong_ordering::less);
  34. EXPECT_EQ(second <=> first, std::strong_ordering::greater);
  35. }
  36. }
  37. }
  38. ////////////////////////////////////////////////////////////////////////////////
  39. } // namespace
  40. } // namespace NYT