Math.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/TestTypes.h>
  9. #include <AzCore/std/math.h>
  10. namespace UnitTest
  11. {
  12. template<typename T>
  13. class StdMathTest : public ::testing::Test
  14. {
  15. };
  16. using MathTestConfigs = ::testing::Types<float, double, long double>;
  17. TYPED_TEST_CASE(StdMathTest, MathTestConfigs);
  18. TYPED_TEST(StdMathTest, LerpOperations)
  19. {
  20. using AZStd::lerp;
  21. using ::testing::Eq;
  22. using T = TypeParam;
  23. constexpr T maxNumber = AZStd::numeric_limits<T>::max();
  24. constexpr T eps = AZStd::numeric_limits<T>::epsilon();
  25. constexpr T a{ 42 };
  26. // exactness: lerp(a,b,0)==a && lerp(a,b,1)==b
  27. EXPECT_THAT(lerp(eps, maxNumber, T(0)), Eq(eps));
  28. EXPECT_THAT(lerp(eps, maxNumber, T(1)), Eq(maxNumber));
  29. // consistency: lerp(a,a,t)==a
  30. EXPECT_THAT(lerp(a, a, T(0.5)), Eq(a));
  31. EXPECT_THAT(lerp(eps, eps, T(0.5)), Eq(eps));
  32. // a few generic tests taken from MathUtilTests.cpp
  33. EXPECT_EQ(T(2.5), lerp(T(2), T(4), T(0.25)));
  34. EXPECT_EQ(T(6.0), lerp(T(2), T(4), T(2.0)));
  35. EXPECT_EQ(T(3.5), lerp(T(2), T(4), T(0.75)));
  36. EXPECT_EQ(T(0.0), lerp(T(2), T(4), T(-1.0)));
  37. }
  38. } // namespace UnitTest