UnitTestFramework.h 1.8 KB

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