tune_ut.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include "tune.h"
  3. struct TDefaultStructA {
  4. };
  5. struct TDefaultStructB {
  6. };
  7. struct TDefaults {
  8. using TStructA = TDefaultStructA;
  9. using TStructB = TDefaultStructB;
  10. static constexpr ui32 Param1 = 42;
  11. static constexpr ui32 Param2 = 42;
  12. };
  13. DeclareTuneTypeParam(TweakStructA, TStructA);
  14. DeclareTuneTypeParam(TweakStructB, TStructB);
  15. DeclareTuneValueParam(TweakParam1, ui32, Param1);
  16. DeclareTuneValueParam(TweakParam2, ui32, Param2);
  17. Y_UNIT_TEST_SUITE(TestTuning) {
  18. Y_UNIT_TEST(Defaults) {
  19. using TTuned = TTune<TDefaults>;
  20. using TunedA = TTuned::TStructA;
  21. using TunedB = TTuned::TStructB;
  22. auto sameA = std::is_same<TDefaultStructA, TunedA>::value;
  23. auto sameB = std::is_same<TDefaultStructB, TunedB>::value;
  24. auto param1 = TTuned::Param1;
  25. auto param2 = TTuned::Param2;
  26. UNIT_ASSERT(sameA);
  27. UNIT_ASSERT(sameB);
  28. UNIT_ASSERT_EQUAL(param1, 42);
  29. UNIT_ASSERT_EQUAL(param2, 42);
  30. }
  31. Y_UNIT_TEST(TuneStructA) {
  32. struct TMyStruct {
  33. };
  34. using TTuned = TTune<TDefaults, TweakStructA<TMyStruct>>;
  35. using TunedA = TTuned::TStructA;
  36. using TunedB = TTuned::TStructB;
  37. //auto sameA = std::is_same<TDefaultStructA, TunedA>::value;
  38. auto sameB = std::is_same<TDefaultStructB, TunedB>::value;
  39. auto param1 = TTuned::Param1;
  40. auto param2 = TTuned::Param2;
  41. auto sameA = std::is_same<TMyStruct, TunedA>::value;
  42. UNIT_ASSERT(sameA);
  43. UNIT_ASSERT(sameB);
  44. UNIT_ASSERT_EQUAL(param1, 42);
  45. UNIT_ASSERT_EQUAL(param2, 42);
  46. }
  47. Y_UNIT_TEST(TuneParam1) {
  48. using TTuned = TTune<TDefaults, TweakParam1<24>>;
  49. using TunedA = TTuned::TStructA;
  50. using TunedB = TTuned::TStructB;
  51. auto sameA = std::is_same<TDefaultStructA, TunedA>::value;
  52. auto sameB = std::is_same<TDefaultStructB, TunedB>::value;
  53. auto param1 = TTuned::Param1;
  54. auto param2 = TTuned::Param2;
  55. UNIT_ASSERT(sameA);
  56. UNIT_ASSERT(sameB);
  57. UNIT_ASSERT_EQUAL(param1, 24);
  58. UNIT_ASSERT_EQUAL(param2, 42);
  59. }
  60. Y_UNIT_TEST(TuneStructAAndParam1) {
  61. struct TMyStruct {
  62. };
  63. using TTuned =
  64. TTune<TDefaults, TweakStructA<TMyStruct>, TweakParam1<24>>;
  65. using TunedA = TTuned::TStructA;
  66. using TunedB = TTuned::TStructB;
  67. //auto sameA = std::is_same<TDefaultStructA, TunedA>::value;
  68. auto sameB = std::is_same<TDefaultStructB, TunedB>::value;
  69. auto param1 = TTuned::Param1;
  70. auto param2 = TTuned::Param2;
  71. auto sameA = std::is_same<TMyStruct, TunedA>::value;
  72. UNIT_ASSERT(sameA);
  73. UNIT_ASSERT(sameB);
  74. UNIT_ASSERT_EQUAL(param1, 24);
  75. UNIT_ASSERT_EQUAL(param2, 42);
  76. }
  77. Y_UNIT_TEST(TuneParam1AndStructA) {
  78. struct TMyStruct {
  79. };
  80. using TTuned =
  81. TTune<TDefaults, TweakParam1<24>, TweakStructA<TMyStruct>>;
  82. using TunedA = TTuned::TStructA;
  83. using TunedB = TTuned::TStructB;
  84. //auto sameA = std::is_same<TDefaultStructA, TunedA>::value;
  85. auto sameB = std::is_same<TDefaultStructB, TunedB>::value;
  86. auto param1 = TTuned::Param1;
  87. auto param2 = TTuned::Param2;
  88. auto sameA = std::is_same<TMyStruct, TunedA>::value;
  89. UNIT_ASSERT(sameA);
  90. UNIT_ASSERT(sameB);
  91. UNIT_ASSERT_EQUAL(param1, 24);
  92. UNIT_ASSERT_EQUAL(param2, 42);
  93. }
  94. }