UnitTestFramework.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include <Jolt.h>
  4. #include <Math/DVec3.h>
  5. #include <Math/Float2.h>
  6. #include "doctest.h"
  7. #if defined(__clang__)
  8. #pragma clang diagnostic ignored "-Wheader-hygiene"
  9. #endif
  10. using namespace JPH;
  11. inline void CHECK_APPROX_EQUAL(float inLHS, float inRHS, float inTolerance = 1.0e-6f)
  12. {
  13. CHECK(abs(inRHS - inLHS) <= inTolerance);
  14. }
  15. inline void CHECK_APPROX_EQUAL(Vec3Arg inLHS, Vec3Arg inRHS, float inTolerance = 1.0e-6f)
  16. {
  17. CHECK(inLHS.IsClose(inRHS, inTolerance * inTolerance));
  18. }
  19. inline void CHECK_APPROX_EQUAL(Vec4Arg inLHS, Vec4Arg inRHS, float inTolerance = 1.0e-6f)
  20. {
  21. CHECK(inLHS.IsClose(inRHS, inTolerance * inTolerance));
  22. }
  23. inline void CHECK_APPROX_EQUAL(Mat44Arg inLHS, Mat44Arg inRHS, float inTolerance = 1.0e-6f)
  24. {
  25. CHECK(inLHS.IsClose(inRHS, inTolerance * inTolerance));
  26. }
  27. inline void CHECK_APPROX_EQUAL(QuatArg inLHS, QuatArg inRHS, float inTolerance = 1.0e-6f)
  28. {
  29. bool close = inLHS.IsClose(inRHS, inTolerance * inTolerance) || inLHS.IsClose(-inRHS, inTolerance * inTolerance);
  30. CHECK(close);
  31. }
  32. #ifdef JPH_USE_AVX
  33. inline void CHECK_APPROX_EQUAL(DVec3Arg inLHS, DVec3Arg inRHS, double inTolerance = 1.0e-6)
  34. {
  35. CHECK(inLHS.IsClose(inRHS, inTolerance * inTolerance));
  36. }
  37. #endif // JPH_USE_AVX
  38. inline void CHECK_APPROX_EQUAL(const Float2 &inLHS, const Float2 &inRHS, float inTolerance = 1.0e-6f)
  39. {
  40. Float2 diff(inLHS.x - inRHS.x, inLHS.y - inRHS.y);
  41. CHECK(Square(diff.x) + Square(diff.y) < inTolerance * inTolerance);
  42. }
  43. // Define the exact random number generator we want to use across platforms for consistency (default_random_engine's implementation is platform specific)
  44. using UnitTestRandom = mt19937;