UnitTestFramework.h 2.1 KB

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