UnitTestFramework.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "doctest.h"
  10. using namespace JPH;
  11. using namespace std;
  12. inline void CHECK_APPROX_EQUAL(float inLHS, float inRHS, float inTolerance = 1.0e-6f)
  13. {
  14. CHECK(abs(inRHS - inLHS) <= inTolerance);
  15. }
  16. inline void CHECK_APPROX_EQUAL(Vec3Arg inLHS, Vec3Arg inRHS, float inTolerance = 1.0e-6f)
  17. {
  18. CHECK(inLHS.IsClose(inRHS, inTolerance * inTolerance));
  19. }
  20. inline void CHECK_APPROX_EQUAL(Vec4Arg inLHS, Vec4Arg inRHS, float inTolerance = 1.0e-6f)
  21. {
  22. CHECK(inLHS.IsClose(inRHS, inTolerance * inTolerance));
  23. }
  24. inline void CHECK_APPROX_EQUAL(Mat44Arg inLHS, Mat44Arg inRHS, float inTolerance = 1.0e-6f)
  25. {
  26. CHECK(inLHS.IsClose(inRHS, inTolerance * inTolerance));
  27. }
  28. inline void CHECK_APPROX_EQUAL(QuatArg inLHS, QuatArg inRHS, float inTolerance = 1.0e-6f)
  29. {
  30. bool close = inLHS.IsClose(inRHS, inTolerance * inTolerance) || inLHS.IsClose(-inRHS, inTolerance * inTolerance);
  31. CHECK(close);
  32. }
  33. #ifdef JPH_USE_AVX2
  34. inline void CHECK_APPROX_EQUAL(DVec3Arg inLHS, DVec3Arg inRHS, double inTolerance = 1.0e-6)
  35. {
  36. CHECK(inLHS.IsClose(inRHS, inTolerance * inTolerance));
  37. }
  38. #endif // JPH_USE_AVX2
  39. inline void CHECK_APPROX_EQUAL(const Float2 &inLHS, const Float2 &inRHS, float inTolerance = 1.0e-6f)
  40. {
  41. Float2 diff(inLHS.x - inRHS.x, inLHS.y - inRHS.y);
  42. CHECK(Square(diff.x) + Square(diff.y) < inTolerance * inTolerance);
  43. }
  44. // Define the exact random number generator we want to use across platforms for consistency (default_random_engine's implementation is platform specific)
  45. using UnitTestRandom = mt19937;