FixedWidthIntegers.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/UnitTest/UnitTest.h>
  9. #include <AzCore/Math/MathUtils.h>
  10. namespace UnitTest
  11. {
  12. inline namespace FixedWidthIntegerTestUtils
  13. {
  14. // Utility to test each possible comparison between LeftType and RightType.
  15. // As there are 64 possible integer combinations for L and R to be tested,
  16. // this utility tests each of the 3 comparison permutations for each
  17. // combination as to avoid having 192 nearly identical test cases.
  18. template<typename LeftType, typename RightType>
  19. void ValidateSafeComparePermutations()
  20. {
  21. // gtest won't pick up on the permutations so print them out for sanity checking
  22. ColoredPrintf(COLOR_YELLOW, "%s\n", AZ_FUNCTION_SIGNATURE);
  23. // Case 1: lhs < rhs
  24. {
  25. constexpr LeftType lhs = (std::numeric_limits<LeftType>::lowest)();
  26. constexpr RightType rhs = (std::numeric_limits<RightType>::max)();
  27. // Expect lhs to be less than rhs
  28. static_assert(AZ::IntegralCompare::LessThan == AZ::SafeIntegralCompare(lhs, rhs));
  29. }
  30. // Case 2: lhs == rhs
  31. {
  32. // Given a lhs and rhs of 0
  33. constexpr LeftType lhs = 0;
  34. constexpr RightType rhs = 0;
  35. // Expect lhs and rhs to be equal
  36. static_assert(AZ::IntegralCompare::Equal == AZ::SafeIntegralCompare(lhs, rhs));
  37. }
  38. // Case 3: lhs > rhs
  39. {
  40. // Given a lhs of > 0 and a rhs of <= 0
  41. constexpr LeftType lhs = (std::numeric_limits<LeftType>::max)();
  42. constexpr RightType rhs = (std::numeric_limits<RightType>::lowest)();
  43. // Expect lhs to be greater than rhs
  44. static_assert(AZ::IntegralCompare::GreaterThan == AZ::SafeIntegralCompare(lhs, rhs));
  45. }
  46. }
  47. // The gtest equality macros do not safely handle integral comparisons between different
  48. // signs and widths so we will wrap around them with our own safe compare function in
  49. // order to test the clamped limits permutations below.
  50. template<typename LeftType, typename RightType>
  51. void SAFE_EXPECT_EQ(LeftType lhs, RightType rhs)
  52. {
  53. EXPECT_EQ(AZ::IntegralCompare::Equal, AZ::SafeIntegralCompare(lhs, rhs));
  54. }
  55. template<typename LeftType, typename RightType>
  56. void SAFE_EXPECT_LT(LeftType lhs, RightType rhs)
  57. {
  58. EXPECT_EQ(AZ::IntegralCompare::LessThan, AZ::SafeIntegralCompare(lhs, rhs));
  59. }
  60. template<typename LeftType, typename RightType>
  61. void SAFE_EXPECT_GT(LeftType lhs, RightType rhs)
  62. {
  63. EXPECT_EQ(AZ::IntegralCompare::GreaterThan, AZ::SafeIntegralCompare(lhs, rhs));
  64. }
  65. // Below are the different cases for integer combinations used by ValidateClampedLimits for each
  66. // possible combination of signedness and size of ValueType and ClampType.
  67. // The basic logic behind each case is the same (namely testing the
  68. // minimum and maximum clamped range of ValueType for a given ClampType) but the
  69. // conditions and expected results are subtley different from one another. As between
  70. // these partial specializations and the 64 explicit test cases covering the
  71. // ClampedIntegralLimits methods every single possible combination of ValueType,
  72. // ClampType and method call in ClampedIntegralLimits
  73. template <typename ClampType, typename ValueType>
  74. constexpr void TestSameSignednessAndEqualSize(ValueType lowestValue, ValueType maxValue)
  75. {
  76. // Given:
  77. // - ValueType is same as ClampType
  78. // Expect the natural numerical limits of ValueType to be equal to the clamped numerical limits of ValueType
  79. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ValueType>::lowest());
  80. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ValueType>::max)());
  81. // Expect the natural numerical limits of ValueType to be equal to the natural numerical limits of ClampType
  82. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ClampType>::lowest());
  83. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ClampType>::max)());
  84. // Clamp the value to the natural numerical range of ClampType
  85. auto[clampedValue1, overflow1] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(lowestValue);
  86. // Expect the original and clamped value to be equal
  87. SAFE_EXPECT_EQ(clampedValue1, lowestValue);
  88. // Expect the value to not have overflowed ClampType's limits
  89. EXPECT_FALSE(overflow1);
  90. // Clamp the value to the natural numerical range of ClampType
  91. auto[clampedValue2, overflow2] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(maxValue);
  92. // Expect the original and clamped value to be equal
  93. SAFE_EXPECT_EQ(clampedValue2, maxValue);
  94. // Expect the value to not have overflowed ClampType's limits
  95. EXPECT_FALSE(overflow2);
  96. }
  97. template <typename ClampType, typename ValueType>
  98. constexpr void TestValueTypeSignedAndValueTypeWider(ValueType lowestValue, ValueType maxValue)
  99. {
  100. // Given:
  101. // - ValueType is signed
  102. // - ClampType is signed or unsigned
  103. // - sizeof(ValueType) > sizeof(ClampType)
  104. // Expect the natural numerical range of ValueType to be larger the clamped numerical range of ValueType
  105. SAFE_EXPECT_GT(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ValueType>::lowest());
  106. SAFE_EXPECT_LT(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ValueType>::max)());
  107. // Expect the clamped numerical limits of ValueType to equal the natural numerical limits of ClampType
  108. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ClampType>::lowest());
  109. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ClampType>::max)());
  110. // Test natural minimum range of ValueType
  111. // Clamp the value to the natural numerical range of ClampType
  112. auto[clampedValue1, overflow1] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(lowestValue);
  113. // Expect the clamped value to be greater than the original value
  114. SAFE_EXPECT_GT(clampedValue1, lowestValue);
  115. // Expect the clamped value to equal ClampType's natural min value
  116. SAFE_EXPECT_EQ(clampedValue1, std::numeric_limits<ClampType>::lowest());
  117. // Expect the value to have overflowed ClampType's limits
  118. EXPECT_TRUE(overflow1);
  119. // Test natural maximum range of ValueType
  120. // Clamp the value to the natural numerical range of ClampType
  121. auto[clampedValue2, overflow2] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(maxValue);
  122. // Expect the clamped value to be less than the original value
  123. SAFE_EXPECT_LT(clampedValue2, maxValue);
  124. // Expect the clamped value to equal ClampType's natural min value
  125. SAFE_EXPECT_EQ(clampedValue2, (std::numeric_limits<ClampType>::max)());
  126. // Expect the value to have overflowed ClampType's limits
  127. EXPECT_TRUE(overflow2);
  128. }
  129. template <typename ClampType, typename ValueType>
  130. constexpr void TestClampTypeSignedAndClampTypeWider(ValueType lowestValue, ValueType maxValue)
  131. {
  132. // Given:
  133. // - ValueType is signed or unsigned
  134. // - ClampType is signed
  135. // - sizeof(ValueType) < sizeof(ClampType)
  136. // Expect the natural numerical limits of ValueType to be equal to the clamped numerical limits of ValueType
  137. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ValueType>::lowest());
  138. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ValueType>::max)());
  139. // Expect the clamped numerical range of ValueType to be smaller than the natural numerical range of ClampType
  140. SAFE_EXPECT_GT(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ClampType>::lowest());
  141. SAFE_EXPECT_LT(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ClampType>::max)());
  142. // Test natural minimum range of ValueType
  143. // Clamp the value to the natural numerical range of ClampType
  144. auto[clampedValue1, overflow1] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(lowestValue);
  145. // Expect the original and clamped value to be equal
  146. SAFE_EXPECT_EQ(clampedValue1, lowestValue);
  147. // Expect the value to not have overflowed ClampType's limits
  148. EXPECT_FALSE(overflow1);
  149. // Test natural maximum range of ValueType
  150. // Clamp the value to the natural numerical range of ClampType
  151. auto[clampedValue2, overflow2] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(maxValue);
  152. // Expect the original and clamped value to be equal
  153. SAFE_EXPECT_EQ(clampedValue2, maxValue);
  154. // Expect the value to not have overflowed ClampType's limits
  155. EXPECT_FALSE(overflow2);
  156. }
  157. template <typename ClampType, typename ValueType>
  158. constexpr void TestValueTypeSignedClampTypeUnsignedAndClampTypeEqualOrWider(ValueType lowestValue, ValueType maxValue)
  159. {
  160. // Given:
  161. // - ValueType is signed
  162. // - ClampType is unsigned
  163. // - sizeof(ValueType) <= sizeof(ClampType)
  164. // Expect the natural min value of ValueType to exceed the clamped numerical limits of ValueType
  165. SAFE_EXPECT_GT(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ValueType>::lowest());
  166. // Expect the natural max value of ValueType to equal the clamped max value of ValueType
  167. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ValueType>::max)());
  168. // Expect the clamped min value of ValueType to equal the natural min value of ClampType
  169. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ClampType>::lowest());
  170. // Expect the clamped max value of ValueType to be less than the natural max value of ClampType
  171. SAFE_EXPECT_LT(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ClampType>::max)());
  172. // Test natural minimum range of ValueType
  173. // Clamp the value to the natural numerical range of ClampType
  174. auto[clampedValue1, overflow1] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(lowestValue);
  175. // Expect the clamped value to be greater than the original value
  176. SAFE_EXPECT_GT(clampedValue1, lowestValue);
  177. // Expect the clamped value to equal ClampType's natural min value
  178. SAFE_EXPECT_EQ(clampedValue1, std::numeric_limits<ClampType>::lowest());
  179. // Expect the value to have overflowed ClampType's limits
  180. EXPECT_TRUE(overflow1);
  181. // Test natural maximum range of ValueType
  182. // Clamp the value to the natural numerical range of ClampType
  183. auto[clampedValue2, overflow2] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(maxValue);
  184. // Expect the original and clamped value to be equal
  185. SAFE_EXPECT_EQ(clampedValue2, maxValue);
  186. // Expect the value to not have overflowed ClampType's limits
  187. EXPECT_TRUE(!overflow2);
  188. }
  189. template <typename ClampType, typename ValueType>
  190. constexpr void TestValueTypeUnsignedClampTypeSignedAndValueTypeEqualOrWider(ValueType lowestValue, ValueType maxValue)
  191. {
  192. // Given:
  193. // - ValueType is unsigned
  194. // - ClampType is signed
  195. // - sizeof(ValueType) >= sizeof(ClampType)
  196. // Expect the natural min value of ValueType to equal the clamped min value of ValueType
  197. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ValueType>::lowest());
  198. // Expect the natural max value of ValueType to exceed the clamped max value of ValueType
  199. SAFE_EXPECT_LT(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ValueType>::max)());
  200. // Expect the clamped min value of ValueType to be greater than the natural min of ClampType
  201. SAFE_EXPECT_GT(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ClampType>::lowest());
  202. // Expect the clamped max value of ValueType to equal the natural max of ClampType
  203. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ClampType>::max)());
  204. // Test natural minimum range of ValueType
  205. // Clamp the value to the natural numerical range of ClampType
  206. auto[clampedValue1, overflow1] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(lowestValue);
  207. // Expect the original and clamped value to be equal
  208. SAFE_EXPECT_EQ(clampedValue1, lowestValue);
  209. // Expect the value to not have overflowed ClampType's limits
  210. EXPECT_FALSE(overflow1);
  211. // Test natural maximum range of ValueType
  212. // Clamp the value to the natural numerical range of ClampType
  213. auto[clampedValue2, overflow2] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(maxValue);
  214. // Expect the clamped value to be less than the original value
  215. SAFE_EXPECT_LT(clampedValue2, maxValue);
  216. // Expect the clamped value to equal ClampType's natural min value
  217. SAFE_EXPECT_EQ(clampedValue2, (std::numeric_limits<ClampType>::max)());
  218. // Expect the value to have overflowed ClampType's limits
  219. EXPECT_TRUE(overflow2);
  220. }
  221. template <typename ClampType, typename ValueType>
  222. constexpr void TestUnsignedAndValueTypeWider(ValueType lowestValue, ValueType maxValue)
  223. {
  224. // Given:
  225. // - ValueType is unsigned
  226. // - ClampType is unsigned
  227. // - sizeof(ValueType) > sizeof(ClampType)
  228. // Expect the natural min value of ValueType to equal the clamped min value of ValueType
  229. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ValueType>::lowest());
  230. // Expect the natural max value of ValueType to exceed the clamped max value of ValueType
  231. SAFE_EXPECT_LT(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ValueType>::max)());
  232. // Expect the clamped numerical limits of ValueType to equal the natural numerical limits of ClampType
  233. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ClampType>::lowest());
  234. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ClampType>::max)());
  235. // Test natural minimum range of ValueType
  236. // Clamp the value to the natural numerical range of ClampType
  237. auto[clampedValue1, overflow1] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(lowestValue);
  238. // Expect the original and clamped value to be equal
  239. SAFE_EXPECT_EQ(clampedValue1, lowestValue);
  240. // Expect the value to not have overflowed ClampType's limits
  241. EXPECT_FALSE(overflow1);
  242. // Test natural maximum range of ValueType
  243. // Clamp the value to the natural numerical range of ClampType
  244. auto[clampedValue2, overflow2] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(maxValue);
  245. // Expect the clamped value to be less than the original value
  246. SAFE_EXPECT_LT(clampedValue2, maxValue);
  247. // Expect the clamped value to equal ClampType's natural min value
  248. SAFE_EXPECT_EQ(clampedValue2, (std::numeric_limits<ClampType>::max)());
  249. // Expect the value to have overflowed ClampType's limits
  250. EXPECT_TRUE(overflow2);
  251. }
  252. template <typename ClampType, typename ValueType>
  253. constexpr void TestUnsignedAndClampTypeWider(ValueType lowestValue, ValueType maxValue)
  254. {
  255. // Given:
  256. // - ValueType is unsigned
  257. // - ClampType is unsigned
  258. // - sizeof(ValueType) < sizeof(ClampType)
  259. // Expect the natural numerical limits of ValueType to be equal to the clamped numerical limits of ValueType
  260. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ValueType>::lowest());
  261. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ValueType>::max)());
  262. // Expect the natural min value of ValueType to equal the clamped min value of ValueType
  263. SAFE_EXPECT_EQ(AZ::ClampedIntegralLimits<ValueType, ClampType>::Min(), std::numeric_limits<ClampType>::lowest());
  264. // Expect the natural max value of ValueType to exceed the clamped max value of ValueType
  265. SAFE_EXPECT_LT(AZ::ClampedIntegralLimits<ValueType, ClampType>::Max(), (std::numeric_limits<ClampType>::max)());
  266. // Test natural minimum range of ValueType
  267. // Clamp the value to the natural numerical range of ClampType
  268. auto[clampedValue1, overflow1] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(lowestValue);
  269. // Expect the original and clamped value to be equal
  270. SAFE_EXPECT_EQ(clampedValue1, lowestValue);
  271. // Expect the value to not have overflowed ClampType's limits
  272. EXPECT_FALSE(overflow1);
  273. // Test natural maximum range of ValueType
  274. // Clamp the value to the natural numerical range of ClampType
  275. auto[clampedValue2, overflow2] = AZ::ClampedIntegralLimits<ValueType, ClampType>::Clamp(maxValue);
  276. // Expect the original and clamped value to be equal
  277. SAFE_EXPECT_EQ(clampedValue2, maxValue);
  278. // Expect the value to not have overflowed ClampType's limits
  279. EXPECT_FALSE(overflow2);
  280. }
  281. template <typename ValueType, typename ClampType, AZ::IntegralTypeDiff TypeDiff = AZ::IntegralTypeCompare<ValueType, ClampType>()>
  282. constexpr void IntegralTypeExpectationCompare(ValueType lowestValue, ValueType maxValue)
  283. {
  284. if constexpr (TypeDiff == AZ::IntegralTypeDiff::LSignedRSignedEqSize || TypeDiff == AZ::IntegralTypeDiff::LUnsignedRUnsignedEqSize)
  285. {
  286. TestSameSignednessAndEqualSize<ClampType>(lowestValue, maxValue);
  287. }
  288. else if constexpr (TypeDiff == AZ::IntegralTypeDiff::LSignedRSignedLWider || TypeDiff == AZ::IntegralTypeDiff::LSignedRUnsignedLWider)
  289. {
  290. TestValueTypeSignedAndValueTypeWider<ClampType>(lowestValue, maxValue);
  291. }
  292. else if constexpr (TypeDiff == AZ::IntegralTypeDiff::LSignedRSignedRWider || TypeDiff == AZ::IntegralTypeDiff::LUnsignedRSignedRWider)
  293. {
  294. TestClampTypeSignedAndClampTypeWider<ClampType>(lowestValue, maxValue);
  295. }
  296. else if constexpr (TypeDiff == AZ::IntegralTypeDiff::LSignedRUnsignedEqSize || TypeDiff == AZ::IntegralTypeDiff::LSignedRUnsignedRWider)
  297. {
  298. TestValueTypeSignedClampTypeUnsignedAndClampTypeEqualOrWider<ClampType>(lowestValue , maxValue);
  299. }
  300. else if constexpr (TypeDiff == AZ::IntegralTypeDiff::LUnsignedRSignedEqSize || TypeDiff == AZ::IntegralTypeDiff::LUnsignedRSignedLWider)
  301. {
  302. TestValueTypeUnsignedClampTypeSignedAndValueTypeEqualOrWider<ClampType>(lowestValue, maxValue);
  303. }
  304. else if constexpr(TypeDiff == AZ::IntegralTypeDiff::LUnsignedRUnsignedLWider)
  305. {
  306. TestUnsignedAndValueTypeWider<ClampType>(lowestValue, maxValue);
  307. }
  308. else if constexpr(TypeDiff == AZ::IntegralTypeDiff::LUnsignedRUnsignedRWider)
  309. {
  310. TestUnsignedAndClampTypeWider<ClampType>(lowestValue, maxValue);
  311. }
  312. }
  313. template<typename ValueType, typename ClampType>
  314. constexpr void ValidateClampedLimits()
  315. {
  316. // gtest won't pick up on the permutations so print them out for sanity checking
  317. ColoredPrintf(COLOR_YELLOW, "%s\n", AZ_FUNCTION_SIGNATURE);
  318. IntegralTypeExpectationCompare<ValueType, ClampType>(std::numeric_limits<ValueType>::lowest(), (std::numeric_limits<ValueType>::max)());
  319. }
  320. }
  321. template<typename ValueType>
  322. class IntegralTypeTestFixture
  323. : public ::testing::Test
  324. {
  325. };
  326. // gtest has a limit of 50 types, whereas we need 64 (one for each integral combination).
  327. // We will work around this by only submitting the 8 integral types to gtest but then
  328. // testing each type against all 8 integral types with a variadic template in order
  329. // to get the 64 integral type combinations we need for full test coverage.
  330. template <class... Types>
  331. struct TypesPack
  332. {
  333. template<typename T>
  334. static void ValidateSafeComparePermutations()
  335. {
  336. (FixedWidthIntegerTestUtils::ValidateSafeComparePermutations<T, Types>(), ...);
  337. }
  338. template<typename T>
  339. static void ValidateClampedLimits()
  340. {
  341. (FixedWidthIntegerTestUtils::ValidateClampedLimits<T, Types>(), ...);
  342. }
  343. };
  344. // The 8 intergral types that each typed test will test with to from each of the
  345. // 64 integral type combinations needed for full test coverage.
  346. using IntegralTypes = TypesPack
  347. <
  348. AZ::s8, AZ::u8, AZ::s16, AZ::u16, AZ::s32, AZ::u32, AZ::s64, AZ::u64
  349. >;
  350. // The 8 integral types that will form the typed tests.
  351. using IntegralTypeTestConfigs = ::testing::Types
  352. <
  353. AZ::s8, AZ::u8, AZ::s16, AZ::u16, AZ::s32, AZ::u32, AZ::s64, AZ::u64
  354. >;
  355. TYPED_TEST_SUITE(IntegralTypeTestFixture, IntegralTypeTestConfigs);
  356. ///////////////////////////////////////////////////////////////////////////
  357. TYPED_TEST(IntegralTypeTestFixture, SafeCompare)
  358. {
  359. IntegralTypes::ValidateSafeComparePermutations<TypeParam>();
  360. }
  361. TYPED_TEST(IntegralTypeTestFixture, ClampedLimits)
  362. {
  363. IntegralTypes::ValidateClampedLimits<TypeParam>();
  364. }
  365. }