enum_indexed_array_ut.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <library/cpp/testing/gtest/gtest.h>
  2. #include <library/cpp/yt/containers/enum_indexed_array.h>
  3. namespace NYT {
  4. namespace {
  5. ////////////////////////////////////////////////////////////////////////////////
  6. DEFINE_ENUM(EColor,
  7. ((Red) (10))
  8. ((Green)(20))
  9. ((Blue) (30))
  10. );
  11. TEST(TEnumIndexedArrayTest, Size)
  12. {
  13. TEnumIndexedArray<EColor, int> arr;
  14. EXPECT_EQ(std::ssize(arr), 21);
  15. }
  16. TEST(TEnumIndexedArrayTest, IsValidIndex)
  17. {
  18. TEnumIndexedArray<EColor, int> arr;
  19. EXPECT_TRUE(arr.IsValidIndex(EColor::Red));
  20. EXPECT_TRUE(arr.IsValidIndex(EColor::Green));
  21. EXPECT_TRUE(arr.IsValidIndex(EColor::Blue));
  22. EXPECT_TRUE(arr.IsValidIndex(static_cast<EColor>(11)));
  23. EXPECT_FALSE(arr.IsValidIndex(static_cast<EColor>(9)));
  24. }
  25. TEST(TEnumIndexedArrayTest, Simple)
  26. {
  27. TEnumIndexedArray<EColor, int> arr;
  28. EXPECT_EQ(arr[EColor::Red], 0);
  29. arr[EColor::Red] = 1;
  30. EXPECT_EQ(arr[EColor::Red], 1);
  31. EXPECT_EQ(arr[EColor::Blue], 0);
  32. }
  33. ////////////////////////////////////////////////////////////////////////////////
  34. } // namespace
  35. } // namespace NYT