diff --git a/tests/QTestExtensions.hpp b/tests/QTestExtensions.hpp index 5d3dd5b4ca..ade89ea942 100644 --- a/tests/QTestExtensions.hpp +++ b/tests/QTestExtensions.hpp @@ -24,8 +24,8 @@ // - QFAIL takes a const char * failure message, and writing custom messages to it is complicated. // // To solve this, we have: -// - QFUZZY_COMPARE (compares floats, or *any other type* using explicitely defined error thresholds. -// To use it, you need to have a fuzzyCompare function ((T, T) -> V), and operator << for QTextStream). +// - QCOMPARE_WITH_ABS_ERROR (compares floats, or *any other type* using explicitely defined error thresholds. +// To use it, you need to have a compareWithAbsError function ((T, T) -> V), and operator << for QTextStream). // - QFAIL_WITH_MESSAGE("some " << streamed << " message"), which builds, writes to, and stringifies // a QTextStream using black magic. // - QCOMPARE_WITH_LAMBDA / QCOMPARE_WITH_FUNCTION, which implements QCOMPARE, but with a user-defined @@ -156,16 +156,16 @@ inline void QTest_failWithMessage( QTest::qFail(qPrintable(QTest_generateCompareFailureMessage(failMessage, actual, expected, actualExpr, expectedExpr, writeAdditionalMessageLines)), file, line); } -// Implements QFUZZY_COMPARE +// Implements QCOMPARE_WITH_ABS_ERROR template -inline auto QTest_fuzzyCompare(const T & actual, const T & expected, const char * actual_expr, const char * expected_expr, int line, const char * file, const V & epsilon) -> decltype(fuzzyCompare(actual, expected)) +inline bool QTest_compareWithAbsError(const T & actual, const T & expected, const char * actual_expr, const char * expected_expr, int line, const char * file, const V & epsilon) { - if (fuzzyCompare(actual, expected) > epsilon) { + if (getErrorDifference(actual, expected) > epsilon) { QTest_failWithMessage( "Compared values are not the same (fuzzy compare)", actual, expected, actual_expr, expected_expr, line, file, [&] (QTextStream & stream) -> QTextStream & { - return stream << "Err tolerance: " << fuzzyCompare((actual), (expected)) << " > " << epsilon; + return stream << "Err tolerance: " << getErrorDifference((actual), (expected)) << " > " << epsilon; }); return false; } @@ -174,20 +174,20 @@ inline auto QTest_fuzzyCompare(const T & actual, const T & expected, const char // Implements a fuzzy QCOMPARE using an explicit epsilon error value. // If you use this, you must have the following functions defined for the types you're using: -// V fuzzyCompare (const T& a, const T& b) (should return the absolute, max difference between a and b) +// V compareWithAbsError (const T& a, const T& b) (should return the absolute, max difference between a and b) // QTextStream & operator << (QTextStream& stream, const T& value) // // Here's an implementation for glm::vec3: -// inline float fuzzyCompare (const glm::vec3 & a, const glm::vec3 & b) { // returns +// inline float compareWithAbsError (const glm::vec3 & a, const glm::vec3 & b) { // returns // return glm::distance(a, b); // } // inline QTextStream & operator << (QTextStream & stream, const T & v) { // return stream << "glm::vec3 { " << v.x << ", " << v.y << ", " << v.z << " }" // } // -#define QFUZZY_COMPARE(actual, expected, epsilon) \ +#define QCOMPARE_WITH_ABS_ERROR(actual, expected, epsilon) \ do { \ - if (!QTest_fuzzyCompare(actual, expected, #actual, #expected, __LINE__, __FILE__, epsilon)) \ + if (!QTest_compareWithAbsError(actual, expected, #actual, #expected, __LINE__, __FILE__, epsilon)) \ return; \ } while(0) diff --git a/tests/physics/src/BulletTestUtils.h b/tests/physics/src/BulletTestUtils.h index 570aaadf45..472f77b2fa 100644 --- a/tests/physics/src/BulletTestUtils.h +++ b/tests/physics/src/BulletTestUtils.h @@ -14,7 +14,7 @@ // Implements functionality in QTestExtensions.hpp for glm types // There are 3 functions in here (which need to be defined for all types that use them): // -// - fuzzyCompare (const T &, const T &) -> V (used by QFUZZY_COMPARE) +// - getErrorDifference (const T &, const T &) -> V (used by QCOMPARE_WITH_ABS_ERROR) // - operator << (QTextStream &, const T &) -> QTextStream & (used by all (additional) test macros) // - errorTest (const T &, const T &, V) -> std::function // (used by QCOMPARE_WITH_RELATIVE_ERROR via QCOMPARE_WITH_LAMBDA) @@ -24,15 +24,15 @@ // fuzzy compare (this is a distance function, basically) // -inline btScalar fuzzyCompare(const btScalar & a, const btScalar & b) { +inline btScalar getErrorDifference(const btScalar & a, const btScalar & b) { return fabs(a - b); } -inline btScalar fuzzyCompare(const btVector3 & a, const btVector3 & b) +inline btScalar getErrorDifference(const btVector3 & a, const btVector3 & b) { return (a - b).length(); } // Matrices are compared element-wise -- if the error value for any element > epsilon, then fail -inline btScalar fuzzyCompare (const btMatrix3x3 & a, const btMatrix3x3 & b) { +inline btScalar getErrorDifference (const btMatrix3x3 & a, const btMatrix3x3 & b) { btScalar maxDiff = 0; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { diff --git a/tests/physics/src/BulletUtilTests.cpp b/tests/physics/src/BulletUtilTests.cpp index ef01311710..d325e4c27c 100644 --- a/tests/physics/src/BulletUtilTests.cpp +++ b/tests/physics/src/BulletUtilTests.cpp @@ -72,5 +72,5 @@ void BulletUtilTests::fromGLMToBullet() { // glm::vec3 b { 2, 0, 5 }; // //// QCOMPARE(10, 22); -// QFUZZY_COMPARE(a, b, 1.0f); +// QCOMPARE_WITH_ABS_ERROR(a, b, 1.0f); //} diff --git a/tests/physics/src/GlmTestUtils.h b/tests/physics/src/GlmTestUtils.h index 1bd2988146..11bb147f8e 100644 --- a/tests/physics/src/GlmTestUtils.h +++ b/tests/physics/src/GlmTestUtils.h @@ -14,7 +14,7 @@ // Implements functionality in QTestExtensions.hpp for glm types -inline float fuzzyCompare(const glm::vec3 & a, const glm::vec3 & b) { +inline float getErrorDifference(const glm::vec3 & a, const glm::vec3 & b) { return glm::distance(a, b); } inline QTextStream & operator << (QTextStream & stream, const glm::vec3 & v) { diff --git a/tests/physics/src/MeshMassPropertiesTests.cpp b/tests/physics/src/MeshMassPropertiesTests.cpp index b0b5e63082..b258849ea5 100644 --- a/tests/physics/src/MeshMassPropertiesTests.cpp +++ b/tests/physics/src/MeshMassPropertiesTests.cpp @@ -76,7 +76,7 @@ void MeshMassPropertiesTests::testParallelAxisTheorem() { // btScalar error; // for (int i = 0; i < 3; ++i) { // for (int j = 0; j < 3; ++j) { -// QFUZZY_COMPARE(bitBoxInertia[i][j], twoSmallBoxesInertia[i][j], acceptableAbsoluteError); +// QCOMPARE_WITH_ABS_ERROR(bitBoxInertia[i][j], twoSmallBoxesInertia[i][j], acceptableAbsoluteError); //// error = bitBoxInertia[i][j] - twoSmallBoxesInertia[i][j]; //// if (fabsf(error) > acceptableAbsoluteError) { //// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : box inertia[" << i << "][" << j << "] off by = " @@ -88,8 +88,8 @@ void MeshMassPropertiesTests::testParallelAxisTheorem() { // Try commenting this out to see what happens when the test fails // twoSmallBoxesInertia[0][2] += 10; - // This now does the same as the above (using the maxDiff fuzzyCompare impl for two btMatrices) - QFUZZY_COMPARE(bitBoxInertia, twoSmallBoxesInertia, acceptableAbsoluteError); + // This now does the same as the above (using the maxDiff getErrorDifference impl for two btMatrices) + QCOMPARE_WITH_ABS_ERROR(bitBoxInertia, twoSmallBoxesInertia, acceptableAbsoluteError); //#ifdef VERBOSE_UNIT_TESTS // printMatrix("expected inertia", bitBoxInertia); @@ -144,9 +144,9 @@ void MeshMassPropertiesTests::testTetrahedron(){ // then fabsf(error) > acceptableRelativeError == fabsf(volume - expectedVolume) > err // where err = acceptableRelativeError * expectedVolume - QFUZZY_COMPARE(volume, expectedVolume, acceptableRelativeError * volume); + QCOMPARE_WITH_ABS_ERROR(volume, expectedVolume, acceptableRelativeError * volume); - // pseudo-hack -- error value is calculated per-element, so QFUZZY_COMPARE will not work. + // pseudo-hack -- error value is calculated per-element, so QCOMPARE_WITH_ABS_ERROR will not work. // QCOMPARE_WITH_FUNCTION and QCOMPARE_WITH_LAMBDA lets you get around this by writing // a custom function to do the actual comparison; printing, etc is done automatically. auto testFunc = [&inertia, &expectedInertia] () { @@ -228,7 +228,7 @@ void MeshMassPropertiesTests::testOpenTetrahedonMesh() { // verify // (expected - actual) / expected > e ==> expected - actual > e * expected - QFUZZY_COMPARE(mesh._volume, expectedVolume, acceptableRelativeError * expectedVolume); + QCOMPARE_WITH_ABS_ERROR(mesh._volume, expectedVolume, acceptableRelativeError * expectedVolume); @@ -239,7 +239,7 @@ void MeshMassPropertiesTests::testOpenTetrahedonMesh() { // } - QFUZZY_COMPARE(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); + QCOMPARE_WITH_ABS_ERROR(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); // error = (mesh._centerOfMass - expectedCenterOfMass).length(); // if (fabsf(error) > acceptableAbsoluteError) { @@ -306,7 +306,7 @@ void MeshMassPropertiesTests::testClosedTetrahedronMesh() { MeshMassProperties mesh(points, triangles); // verify - QFUZZY_COMPARE(mesh._volume, expectedVolume, acceptableRelativeError); + QCOMPARE_WITH_ABS_ERROR(mesh._volume, expectedVolume, acceptableRelativeError); // btScalar error; // error = (mesh._volume - expectedVolume) / expectedVolume; // if (fabsf(error) > acceptableRelativeError) { @@ -315,7 +315,7 @@ void MeshMassPropertiesTests::testClosedTetrahedronMesh() { // } - QFUZZY_COMPARE(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); + QCOMPARE_WITH_ABS_ERROR(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); // error = (mesh._centerOfMass - expectedCenterOfMass).length(); // if (fabsf(error) > acceptableAbsoluteError) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR : centerOfMass of tetrahedron off by = " @@ -352,14 +352,14 @@ void MeshMassPropertiesTests::testClosedTetrahedronMesh() { mesh.computeMassProperties(points, triangles); // verify -// QFUZZY_COMPARE(mesh._volume, expectedVolume, acceptableRelativeError * expectedVolume); +// QCOMPARE_WITH_ABS_ERROR(mesh._volume, expectedVolume, acceptableRelativeError * expectedVolume); //// error = (mesh._volume - expectedVolume) / expectedVolume; //// if (fabsf(error) > acceptableRelativeError) { //// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : volume of tetrahedron off by = " //// << error << std::endl; //// } // -// QFUZZY_COMPARE(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); +// QCOMPARE_WITH_ABS_ERROR(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); //// error = (mesh._centerOfMass - expectedCenterOfMass).length(); //// if (fabsf(error) > acceptableAbsoluteError) { //// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : centerOfMass of tetrahedron off by = " @@ -448,7 +448,7 @@ void MeshMassPropertiesTests::testBoxAsMesh() { // verify - QFUZZY_COMPARE(mesh._volume, expectedVolume, acceptableRelativeError * expectedVolume); + QCOMPARE_WITH_ABS_ERROR(mesh._volume, expectedVolume, acceptableRelativeError * expectedVolume); // btScalar error; // error = (mesh._volume - expectedVolume) / expectedVolume; // if (fabsf(error) > acceptableRelativeError) { @@ -456,7 +456,7 @@ void MeshMassPropertiesTests::testBoxAsMesh() { // << error << std::endl; // } - QFUZZY_COMPARE(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); + QCOMPARE_WITH_ABS_ERROR(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); // error = (mesh._centerOfMass - expectedCenterOfMass).length(); // if (fabsf(error) > acceptableAbsoluteError) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR : centerOfMass of tetrahedron off by = " @@ -465,7 +465,7 @@ void MeshMassPropertiesTests::testBoxAsMesh() { // do this twice to avoid divide-by-zero? - QFUZZY_COMPARE(mesh._inertia, expectedInertia, acceptableAbsoluteError); + QCOMPARE_WITH_ABS_ERROR(mesh._inertia, expectedInertia, acceptableAbsoluteError); QCOMPARE_WITH_RELATIVE_ERROR(mesh._inertia, expectedInertia, acceptableRelativeError); // for (int i = 0; i < 3; ++i) { // for (int j = 0; j < 3; ++j) { diff --git a/tests/physics/src/ShapeColliderTests.cpp b/tests/physics/src/ShapeColliderTests.cpp index 1b22470594..e23491f61a 100644 --- a/tests/physics/src/ShapeColliderTests.cpp +++ b/tests/physics/src/ShapeColliderTests.cpp @@ -94,7 +94,7 @@ void ShapeColliderTests::sphereTouchesSphere() { glm::vec3 expectedContactPoint = sphereA.getTranslation() + radiusA * glm::normalize(AtoB); QCOMPARE(collision->_contactPoint, expectedContactPoint); - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); } // collide B to A... @@ -104,12 +104,12 @@ void ShapeColliderTests::sphereTouchesSphere() { // penetration points from sphereA into sphereB CollisionInfo* collision = collisions.getCollision(numCollisions - 1); - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // contactPoint is on surface of sphereA glm::vec3 BtoA = sphereA.getTranslation() - sphereB.getTranslation(); glm::vec3 expectedContactPoint = sphereB.getTranslation() + radiusB * glm::normalize(BtoA); - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); } } @@ -177,11 +177,11 @@ void ShapeColliderTests::sphereTouchesCapsule() { // penetration points from sphereA into capsuleB CollisionInfo* collision = collisions.getCollision(numCollisions - 1); glm::vec3 expectedPenetration = (radialOffset - totalRadius) * xAxis; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // contactPoint is on surface of sphereA glm::vec3 expectedContactPoint = sphereA.getTranslation() - radiusA * xAxis; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); // capsuleB collides with sphereA QCOMPARE(ShapeCollider::collideShapes(&capsuleB, &sphereA, collisions), true); @@ -194,7 +194,7 @@ void ShapeColliderTests::sphereTouchesCapsule() { // the ShapeCollider swapped the order of the shapes expectedPenetration *= -1.0f; } - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // contactPoint is on surface of capsuleB glm::vec3 BtoA = sphereA.getTranslation() - capsuleB.getTranslation(); @@ -205,7 +205,7 @@ void ShapeColliderTests::sphereTouchesCapsule() { closestApproach = sphereA.getTranslation() - glm::dot(BtoA, yAxis) * yAxis; expectedContactPoint = closestApproach - radiusB * glm::normalize(BtoA - closestApproach); } - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); } { // sphereA hits end cap at axis glm::vec3 axialOffset = (halfHeightB + alpha * radiusA + beta * radiusB) * yAxis; @@ -217,12 +217,12 @@ void ShapeColliderTests::sphereTouchesCapsule() { // penetration points from sphereA into capsuleB CollisionInfo* collision = collisions.getCollision(numCollisions - 1); glm::vec3 expectedPenetration = - ((1.0f - alpha) * radiusA + (1.0f - beta) * radiusB) * yAxis; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // contactPoint is on surface of sphereA glm::vec3 expectedContactPoint = sphereA.getTranslation() - radiusA * yAxis; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -246,7 +246,7 @@ void ShapeColliderTests::sphereTouchesCapsule() { // the ShapeCollider swapped the order of the shapes expectedPenetration *= -1.0f; } - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -263,7 +263,7 @@ void ShapeColliderTests::sphereTouchesCapsule() { expectedContactPoint = axialOffset - radiusA * yAxis; } - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -287,7 +287,7 @@ void ShapeColliderTests::sphereTouchesCapsule() { CollisionInfo* collision = collisions.getCollision(numCollisions - 1); glm::vec3 expectedPenetration = ((1.0f - alpha) * radiusA + (1.0f - beta) * radiusB) * yAxis; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // float inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -297,7 +297,7 @@ void ShapeColliderTests::sphereTouchesCapsule() { // contactPoint is on surface of sphereA glm::vec3 expectedContactPoint = sphereA.getTranslation() + radiusA * yAxis; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -321,7 +321,7 @@ void ShapeColliderTests::sphereTouchesCapsule() { // the ShapeCollider swapped the order of the shapes expectedPenetration *= -1.0f; } - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -337,7 +337,7 @@ void ShapeColliderTests::sphereTouchesCapsule() { // the ShapeCollider swapped the order of the shapes expectedContactPoint = axialOffset + radiusA * yAxis; } - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -526,7 +526,7 @@ void ShapeColliderTests::capsuleTouchesCapsule() { CollisionInfo* collision = collisions.getCollision(numCollisions - 1); glm::vec3 expectedPenetration = overlap * xAxis; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // float inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -535,7 +535,7 @@ void ShapeColliderTests::capsuleTouchesCapsule() { // } glm::vec3 expectedContactPoint = capsuleA.getTranslation() + radiusA * xAxis; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -555,7 +555,7 @@ void ShapeColliderTests::capsuleTouchesCapsule() { // } collision = collisions.getCollision(numCollisions - 1); expectedPenetration = - overlap * xAxis; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -564,7 +564,7 @@ void ShapeColliderTests::capsuleTouchesCapsule() { // } expectedContactPoint = capsuleB.getTranslation() - (radiusB + halfHeightB) * xAxis; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -593,7 +593,7 @@ void ShapeColliderTests::capsuleTouchesCapsule() { CollisionInfo* collision = collisions.getCollision(numCollisions - 1); glm::vec3 expectedPenetration = overlap * zAxis; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // float inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -602,7 +602,7 @@ void ShapeColliderTests::capsuleTouchesCapsule() { // } glm::vec3 expectedContactPoint = capsuleA.getTranslation() + radiusA * zAxis + shift * yAxis; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ @@ -780,7 +780,7 @@ void ShapeColliderTests::sphereTouchesAACubeFaces() { break; } - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // if (glm::distance(expectedPenetration, collision->_penetration) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: penetration = " << collision->_penetration // << " expected " << expectedPenetration << " faceNormal = " << faceNormal << std::endl; @@ -788,7 +788,7 @@ void ShapeColliderTests::sphereTouchesAACubeFaces() { glm::vec3 expectedContact = sphereCenter - sphereRadius * faceNormal; - QFUZZY_COMPARE(collision->_contactPoint, expectedContact, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContact, EPSILON); // if (glm::distance(expectedContact, collision->_contactPoint) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: contactaPoint = " << collision->_contactPoint // << " expected " << expectedContact << " faceNormal = " << faceNormal << std::endl; @@ -824,14 +824,14 @@ void ShapeColliderTests::sphereTouchesAACubeFaces() { } glm::vec3 expectedPenetration = - overlap * faceNormal; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // if (glm::distance(expectedPenetration, collision->_penetration) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: penetration = " << collision->_penetration // << " expected " << expectedPenetration << " faceNormal = " << faceNormal << std::endl; // } glm::vec3 expectedContact = sphereCenter - sphereRadius * faceNormal; - QFUZZY_COMPARE(collision->_contactPoint, expectedContact, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContact, EPSILON); // if (glm::distance(expectedContact, collision->_contactPoint) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: contactaPoint = " << collision->_contactPoint // << " expected " << expectedContact << " faceNormal = " << faceNormal << std::endl; @@ -896,14 +896,14 @@ void ShapeColliderTests::sphereTouchesAACubeEdges() { // << " edgeNormal = " << edgeNormal << std::endl; break; } - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // if (glm::distance(expectedPenetration, collision->_penetration) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: penetration = " << collision->_penetration // << " expected " << expectedPenetration << " edgeNormal = " << edgeNormal << std::endl; // } glm::vec3 expectedContact = sphereCenter - sphereRadius * edgeNormal; - QFUZZY_COMPARE(collision->_contactPoint, expectedContact, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContact, EPSILON); // if (glm::distance(expectedContact, collision->_contactPoint) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: contactaPoint = " << collision->_contactPoint // << " expected " << expectedContact << " edgeNormal = " << edgeNormal << std::endl; @@ -962,14 +962,14 @@ void ShapeColliderTests::sphereTouchesAACubeCorners() { } glm::vec3 expectedPenetration = - overlap * offsetAxis; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); // if (glm::distance(expectedPenetration, collision->_penetration) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: penetration = " << collision->_penetration // << " expected " << expectedPenetration << " cornerNormal = " << cornerNormal << std::endl; // } glm::vec3 expectedContact = sphereCenter - sphereRadius * offsetAxis; - QFUZZY_COMPARE(collision->_contactPoint, expectedContact, EPSILON); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContact, EPSILON); // if (glm::distance(expectedContact, collision->_contactPoint) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: contactaPoint = " << collision->_contactPoint // << " expected " << expectedContact << " cornerNormal = " << cornerNormal << std::endl; @@ -1331,7 +1331,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // penetration points from capsule into cube glm::vec3 expectedPenetration = - overlap * faceNormal; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); // float inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > allowableError) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1343,7 +1343,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // contactPoint is on surface of capsule glm::vec3 expectedContactPoint = collidingPoint - capsuleRadius * faceNormal; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > allowableError) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1414,7 +1414,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // penetration points from capsule into cube glm::vec3 expectedPenetration = - overlap * edgeNormal; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); // float inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > allowableError) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1426,7 +1426,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // contactPoint is on surface of capsule glm::vec3 expectedContactPoint = collidingPoint - capsuleRadius * edgeNormal; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > allowableError) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1489,7 +1489,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // penetration points from capsule into cube glm::vec3 expectedPenetration = - overlap * cornerNormal; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); // float inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > allowableError) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1501,7 +1501,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // contactPoint is on surface of capsule glm::vec3 expectedContactPoint = collidingPoint - capsuleRadius * cornerNormal; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > allowableError) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1577,7 +1577,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // penetration points from capsule into cube glm::vec3 expectedPenetration = - overlap * deflectedNormal; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); // float inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > allowableError / capsuleLength) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1589,7 +1589,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // contactPoint is on surface of capsule glm::vec3 expectedContactPoint = axisPoint - capsuleRadius * deflectedNormal; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > allowableError / capsuleLength) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1660,7 +1660,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // penetration points from capsule into cube glm::vec3 expectedPenetration = overlap * penetrationNormal; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); // float inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > allowableError) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1672,7 +1672,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // contactPoint is on surface of capsule glm::vec3 expectedContactPoint = collidingPoint + capsuleRadius * penetrationNormal; - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); // inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); // if (fabsf(inaccuracy) > allowableError) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1753,7 +1753,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { CollisionInfo* collision = collisions.getCollision(k); // penetration points from capsule into cube glm::vec3 expectedPenetration = - overlap * faceNormal; - QFUZZY_COMPARE(collision->_penetration, expectedPenetration, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); // float inaccuracy = glm::length(collision->_penetration - expectedPenetration); // if (fabsf(inaccuracy) > allowableError) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1770,7 +1770,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { float length1 = glm::length(collision->_contactPoint - expectedContactPoints[1]); glm::vec3 expectedContactPoint = (length0 < length1) ? expectedContactPoints[0] : expectedContactPoints[1]; // contactPoint is on surface of capsule - QFUZZY_COMPARE(collision->_contactPoint, expectedContactPoint, allowableError); + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); // inaccuracy = (length0 < length1) ? length0 : length1; // if (fabsf(inaccuracy) > allowableError) { // std::cout << __FILE__ << ":" << __LINE__ @@ -1805,7 +1805,7 @@ void ShapeColliderTests::rayHitsSphere() { // } float expectedDistance = startDistance - radius; - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, startDistance * EPSILON); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // if (relativeError > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray sphere intersection distance error = " << relativeError << std::endl; @@ -1828,7 +1828,7 @@ void ShapeColliderTests::rayHitsSphere() { // } float expectedDistance = SQUARE_ROOT_OF_2 * startDistance - radius; - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, startDistance * EPSILON); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // if (relativeError > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray sphere intersection distance error = " << relativeError << std::endl; @@ -1860,7 +1860,7 @@ void ShapeColliderTests::rayHitsSphere() { // } float expectedDistance = startDistance - radius; - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, startDistance * EPSILON); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // if (relativeError > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray sphere intersection distance error = " @@ -1987,7 +1987,7 @@ void ShapeColliderTests::rayHitsCapsule() { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl; // } float expectedDistance = startDistance - radius; - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, startDistance * EPSILON); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // if (relativeError > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " @@ -2009,7 +2009,7 @@ void ShapeColliderTests::rayHitsCapsule() { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl; // } float expectedDistance = startDistance - radius; - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, startDistance * EPSILON); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // if (relativeError > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " @@ -2027,7 +2027,7 @@ void ShapeColliderTests::rayHitsCapsule() { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl; // } float expectedDistance = startDistance - radius; - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, startDistance * EPSILON); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // if (relativeError > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " @@ -2047,7 +2047,7 @@ void ShapeColliderTests::rayHitsCapsule() { float expectedDistance = startDistance - radius * sqrtf(2.0f * delta); // using small angle approximation of cosine // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // for edge cases we allow a LOT of error - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, startDistance * EDGE_CASE_SLOP_FACTOR * EPSILON); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EDGE_CASE_SLOP_FACTOR * EPSILON); // if (relativeError > EDGE_CASE_SLOP_FACTOR * EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " // << relativeError << std::endl; @@ -2065,7 +2065,7 @@ void ShapeColliderTests::rayHitsCapsule() { float expectedDistance = startDistance - radius * sqrtf(2.0f * delta); // using small angle approximation of cosine // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // for edge cases we allow a LOT of error - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, startDistance * EPSILON * EDGE_CASE_SLOP_FACTOR); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON * EDGE_CASE_SLOP_FACTOR); // if (relativeError > EDGE_CASE_SLOP_FACTOR * EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " // << relativeError << std::endl; @@ -2083,7 +2083,7 @@ void ShapeColliderTests::rayHitsCapsule() { float expectedDistance = startDistance - radius * sqrtf(2.0f * delta); // using small angle approximation of cosine float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // for edge cases we allow a LOT of error - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, startDistance * EPSILON * EDGE_CASE_SLOP_FACTOR); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON * EDGE_CASE_SLOP_FACTOR); // if (relativeError > EDGE_CASE_SLOP_FACTOR * EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " // << relativeError << std::endl; @@ -2176,7 +2176,7 @@ void ShapeColliderTests::rayHitsPlane() { float expectedDistance = SQUARE_ROOT_OF_3 * planeDistanceFromOrigin; - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, planeDistanceFromOrigin * EPSILON); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, planeDistanceFromOrigin * EPSILON); // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / planeDistanceFromOrigin; // if (relativeError > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray plane intersection distance error = " @@ -2206,7 +2206,7 @@ void ShapeColliderTests::rayHitsPlane() { // } float expectedDistance = SQUARE_ROOT_OF_3 * planeDistanceFromOrigin; - QFUZZY_COMPARE(intersection._hitDistance, expectedDistance, planeDistanceFromOrigin * EPSILON); + QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, planeDistanceFromOrigin * EPSILON); // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / planeDistanceFromOrigin; // if (relativeError > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray plane intersection distance error = " @@ -2353,13 +2353,13 @@ void ShapeColliderTests::rayHitsAACube() { // std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit cube face" << std::endl; // break; // } - QFUZZY_COMPARE(glm::dot(faceNormal, intersection._hitNormal), 1.0f, EPSILON); + QCOMPARE_WITH_ABS_ERROR(glm::dot(faceNormal, intersection._hitNormal), 1.0f, EPSILON); // if (glm::abs(1.0f - glm::dot(faceNormal, intersection._hitNormal)) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ // << " ERROR: ray should hit cube face with normal " << faceNormal // << " but found different normal " << intersection._hitNormal << std::endl; // } - QFUZZY_COMPARE(facePoint, intersection.getIntersectionPoint(), EPSILON); + QCOMPARE_WITH_ABS_ERROR(facePoint, intersection.getIntersectionPoint(), EPSILON); // if (glm::distance(facePoint, intersection.getIntersectionPoint()) > EPSILON) { // std::cout << __FILE__ << ":" << __LINE__ // << " ERROR: ray should hit cube face at " << facePoint diff --git a/tests/shared/src/AngularConstraintTests.cpp b/tests/shared/src/AngularConstraintTests.cpp index 14a50ab07f..9d8e9af350 100644 --- a/tests/shared/src/AngularConstraintTests.cpp +++ b/tests/shared/src/AngularConstraintTests.cpp @@ -21,7 +21,7 @@ QTEST_MAIN(AngularConstraintTests) // Computes the error value between two quaternions (using glm::dot) -float fuzzyCompare(const glm::quat & a, const glm::quat & b) { +float getErrorDifference(const glm::quat & a, const glm::quat & b) { return fabsf(glm::dot(a, b) - 1.0f); } QTextStream & operator << (QTextStream & stream, const glm::quat & q) { @@ -77,7 +77,7 @@ void AngularConstraintTests::testHingeConstraint() { QVERIFY2(constrained, "HingeConstraint should clamp()"); QVERIFY2(newRotation != rotation, "HingeConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } { // test just outside max edge of constraint float angle = maxAngle + 0.001f; @@ -88,7 +88,7 @@ void AngularConstraintTests::testHingeConstraint() { QVERIFY2(constrained, "HingeConstraint should clamp()"); QVERIFY2(newRotation != rotation, "HingeConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, rotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, rotation, EPSILON); } { // test far outside min edge of constraint (wraps around to max) float angle = minAngle - 0.75f * (TWO_PI - (maxAngle - minAngle)); @@ -100,7 +100,7 @@ void AngularConstraintTests::testHingeConstraint() { glm::quat expectedRotation = glm::angleAxis(maxAngle, yAxis); QVERIFY2(constrained, "HingeConstraint should clamp()"); QVERIFY2(newRotation != rotation, "HingeConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } { // test far outside max edge of constraint (wraps around to min) float angle = maxAngle + 0.75f * (TWO_PI - (maxAngle - minAngle)); @@ -112,7 +112,7 @@ void AngularConstraintTests::testHingeConstraint() { QVERIFY2(constrained, "HingeConstraint should clamp()"); QVERIFY2(newRotation != rotation, "HingeConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } float ACCEPTABLE_ERROR = 1.0e-4f; @@ -128,7 +128,7 @@ void AngularConstraintTests::testHingeConstraint() { QVERIFY2(constrained, "HingeConstraint should clamp()"); QVERIFY2(newRotation != rotation, "HingeConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, ACCEPTABLE_ERROR); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, ACCEPTABLE_ERROR); } { // test way off rotation > maxAngle float offAngle = 0.5f; @@ -143,7 +143,7 @@ void AngularConstraintTests::testHingeConstraint() { QVERIFY2(constrained, "HingeConstraint should clamp()"); QVERIFY2(newRotation != rotation, "HingeConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } { // test way off rotation < minAngle float offAngle = 0.5f; @@ -158,7 +158,7 @@ void AngularConstraintTests::testHingeConstraint() { QVERIFY2(constrained, "HingeConstraint should clamp()"); QVERIFY2(newRotation != rotation, "HingeConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } { // test way off rotation > maxAngle with wrap over to minAngle float offAngle = -0.5f; @@ -173,7 +173,7 @@ void AngularConstraintTests::testHingeConstraint() { QVERIFY2(constrained, "HingeConstraint should clamp()"); QVERIFY2(newRotation != rotation, "HingeConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } { // test way off rotation < minAngle with wrap over to maxAngle float offAngle = -0.6f; @@ -188,7 +188,7 @@ void AngularConstraintTests::testHingeConstraint() { QVERIFY2(constrained, "HingeConstraint should clamp()"); QVERIFY2(newRotation != rotation, "HingeConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } delete c; } @@ -271,7 +271,7 @@ void AngularConstraintTests::testConeRollerConstraint() { QVERIFY2(constrained, "ConeRollerConstraint should clamp()"); QVERIFY2(newRotation != rotation, "ConeRollerConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } { // test just outside max edge of roll glm::quat rotation = glm::angleAxis(maxAngleZ + deltaAngle, expectedConeAxis); @@ -282,7 +282,7 @@ void AngularConstraintTests::testConeRollerConstraint() { QVERIFY2(constrained, "ConeRollerConstraint should clamp()"); QVERIFY2(newRotation != rotation, "ConeRollerConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } deltaAngle = 0.25f * expectedConeAngle; { // test far outside cone and min roll @@ -299,7 +299,7 @@ void AngularConstraintTests::testConeRollerConstraint() { QVERIFY2(constrained, "ConeRollerConstraint should clamp()"); QVERIFY2(newRotation != rotation, "ConeRollerConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } { // test far outside cone and max roll glm::quat roll = glm::angleAxis(maxAngleZ + deltaAngle, expectedConeAxis); @@ -315,7 +315,7 @@ void AngularConstraintTests::testConeRollerConstraint() { QVERIFY2(constrained, "ConeRollerConstraint should clamp()"); QVERIFY2(newRotation != rotation, "ConeRollerConstraint should change rotation"); - QFUZZY_COMPARE(newRotation, expectedRotation, EPSILON); + QCOMPARE_WITH_ABS_ERROR(newRotation, expectedRotation, EPSILON); } delete c; } diff --git a/tests/shared/src/AngularConstraintTests.h b/tests/shared/src/AngularConstraintTests.h index ea950471cd..ea40c4a4fb 100644 --- a/tests/shared/src/AngularConstraintTests.h +++ b/tests/shared/src/AngularConstraintTests.h @@ -21,9 +21,9 @@ private slots: void testConeRollerConstraint(); }; -// Use QFUZZY_COMPARE and define it for glm::quat +// Use QCOMPARE_WITH_ABS_ERROR and define it for glm::quat #include -float fuzzyCompare (const glm::quat & a, const glm::quat & b); +float getErrorDifference (const glm::quat & a, const glm::quat & b); QTextStream & operator << (QTextStream & stream, const glm::quat & q); #include "../QTestExtensions.hpp" diff --git a/tests/shared/src/MovingMinMaxAvgTests.cpp b/tests/shared/src/MovingMinMaxAvgTests.cpp index 6ee86f9464..b96d84df61 100644 --- a/tests/shared/src/MovingMinMaxAvgTests.cpp +++ b/tests/shared/src/MovingMinMaxAvgTests.cpp @@ -64,8 +64,8 @@ void MovingMinMaxAvgTests::testQuint64() { QCOMPARE(stats.getMin(), min); QCOMPARE(stats.getMax(), max); - QFUZZY_COMPARE((float) stats.getAverage() / (float) average, 1.0f, EPSILON); - QFUZZY_COMPARE((float) stats.getAverage(), (float) average, EPSILON); + QCOMPARE_WITH_ABS_ERROR((float) stats.getAverage() / (float) average, 1.0f, EPSILON); + QCOMPARE_WITH_ABS_ERROR((float) stats.getAverage(), (float) average, EPSILON); // QCOMPARE(fabsf( // (float)stats.getAverage() / (float)average - 1.0f diff --git a/tests/shared/src/MovingMinMaxAvgTests.h b/tests/shared/src/MovingMinMaxAvgTests.h index cca7ff4688..4fc16b80f5 100644 --- a/tests/shared/src/MovingMinMaxAvgTests.h +++ b/tests/shared/src/MovingMinMaxAvgTests.h @@ -14,7 +14,7 @@ #include -inline float fuzzyCompare (float a, float b) { +inline float getErrorDifference (float a, float b) { return fabsf(a - b); }