UnitTestFramework.h 2.2 KB

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