From 488f6aa7d85f2c64f39408ac21a5bdfd46c7dd62 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 12 Aug 2015 13:34:23 -0700 Subject: [PATCH 1/6] fix bug in ElbowConstraint::apply() --- libraries/animation/src/ElbowConstraint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/animation/src/ElbowConstraint.cpp b/libraries/animation/src/ElbowConstraint.cpp index 8c7fec7b6f..a6b2210644 100644 --- a/libraries/animation/src/ElbowConstraint.cpp +++ b/libraries/animation/src/ElbowConstraint.cpp @@ -67,7 +67,7 @@ bool ElbowConstraint::apply(glm::quat& rotation) const { // update rotation const float MIN_SWING_REAL_PART = 0.99999f; - if (twistWasClamped || fabsf(swingRotation.w < MIN_SWING_REAL_PART)) { + if (twistWasClamped || fabsf(swingRotation.w) < MIN_SWING_REAL_PART) { if (twistWasClamped) { twistRotation = glm::angleAxis(clampedTwistAngle, _axis); } From ba5346aee7e52e43fb1dcc69aeee84d76128faa4 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 12 Aug 2015 13:37:59 -0700 Subject: [PATCH 2/6] move GlmTestUtils.h to GLMTestUtils.h --- tests/physics/src/BulletUtilTests.cpp | 2 +- tests/physics/src/{GlmTestUtils.h => GLMTestUtils.h} | 6 +++--- tests/physics/src/MeshMassPropertiesTests.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename tests/physics/src/{GlmTestUtils.h => GLMTestUtils.h} (89%) diff --git a/tests/physics/src/BulletUtilTests.cpp b/tests/physics/src/BulletUtilTests.cpp index 181d22327e..a52e407aab 100644 --- a/tests/physics/src/BulletUtilTests.cpp +++ b/tests/physics/src/BulletUtilTests.cpp @@ -17,7 +17,7 @@ #include // Add additional qtest functionality (the include order is important!) -#include "GlmTestUtils.h" +#include "GLMTestUtils.h" #include "../QTestExtensions.h" // Constants diff --git a/tests/physics/src/GlmTestUtils.h b/tests/physics/src/GLMTestUtils.h similarity index 89% rename from tests/physics/src/GlmTestUtils.h rename to tests/physics/src/GLMTestUtils.h index 20bc14d5e0..ef63689419 100644 --- a/tests/physics/src/GlmTestUtils.h +++ b/tests/physics/src/GLMTestUtils.h @@ -1,5 +1,5 @@ // -// GlmTestUtils.h +// GLMTestUtils.h // tests/physics/src // // Created by Seiji Emery on 6/22/15 @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_GlmTestUtils_h -#define hifi_GlmTestUtils_h +#ifndef hifi_GLMTestUtils_h +#define hifi_GLMTestUtils_h #include #include diff --git a/tests/physics/src/MeshMassPropertiesTests.cpp b/tests/physics/src/MeshMassPropertiesTests.cpp index e88bcae1b7..8295abfef8 100644 --- a/tests/physics/src/MeshMassPropertiesTests.cpp +++ b/tests/physics/src/MeshMassPropertiesTests.cpp @@ -16,7 +16,7 @@ // Add additional qtest functionality (the include order is important!) #include "BulletTestUtils.h" -#include "GlmTestUtils.h" +#include "GLMTestUtils.h" #include "../QTestExtensions.h" const btScalar acceptableRelativeError(1.0e-5f); From cae77cfd767c2788f15f791528c991096acc98fe Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 12 Aug 2015 13:51:40 -0700 Subject: [PATCH 3/6] move GLMTestUtils.h where all tests can find it --- tests/CMakeLists.txt | 4 ++-- tests/{physics/src => }/GLMTestUtils.h | 1 + tests/QTestExtensions.h | 2 ++ tests/physics/src/BulletUtilTests.cpp | 1 - tests/physics/src/MeshMassPropertiesTests.cpp | 1 - 5 files changed, 5 insertions(+), 4 deletions(-) rename tests/{physics/src => }/GLMTestUtils.h (99%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c352b55515..1593b649a0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,7 +12,7 @@ foreach(DIR ${TEST_SUBDIRS}) endif() endforeach() -file(GLOB SHARED_TEST_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") +file(GLOB SHARED_TEST_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h " "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") add_custom_target("test-extensions" SOURCES "${SHARED_TEST_HEADER_FILES}") @@ -34,4 +34,4 @@ add_custom_target("all-tests" set_target_properties("all-tests" PROPERTIES FOLDER "hidden/test-targets") set_target_properties("all-tests" PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE - EXCLUDE_FROM_ALL TRUE) \ No newline at end of file + EXCLUDE_FROM_ALL TRUE) diff --git a/tests/physics/src/GLMTestUtils.h b/tests/GLMTestUtils.h similarity index 99% rename from tests/physics/src/GLMTestUtils.h rename to tests/GLMTestUtils.h index ef63689419..6559e9f3c9 100644 --- a/tests/physics/src/GLMTestUtils.h +++ b/tests/GLMTestUtils.h @@ -20,6 +20,7 @@ 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) { return stream << "glm::vec3 { " << v.x << ", " << v.y << ", " << v.z << " }"; } diff --git a/tests/QTestExtensions.h b/tests/QTestExtensions.h index c034e9c290..d1918ebed8 100644 --- a/tests/QTestExtensions.h +++ b/tests/QTestExtensions.h @@ -15,6 +15,8 @@ #include #include +#include "GLMTestUtils.h" + // Implements several extensions to QtTest. // // Problems with QtTest: diff --git a/tests/physics/src/BulletUtilTests.cpp b/tests/physics/src/BulletUtilTests.cpp index a52e407aab..132d655274 100644 --- a/tests/physics/src/BulletUtilTests.cpp +++ b/tests/physics/src/BulletUtilTests.cpp @@ -17,7 +17,6 @@ #include // Add additional qtest functionality (the include order is important!) -#include "GLMTestUtils.h" #include "../QTestExtensions.h" // Constants diff --git a/tests/physics/src/MeshMassPropertiesTests.cpp b/tests/physics/src/MeshMassPropertiesTests.cpp index 8295abfef8..825721641f 100644 --- a/tests/physics/src/MeshMassPropertiesTests.cpp +++ b/tests/physics/src/MeshMassPropertiesTests.cpp @@ -16,7 +16,6 @@ // Add additional qtest functionality (the include order is important!) #include "BulletTestUtils.h" -#include "GLMTestUtils.h" #include "../QTestExtensions.h" const btScalar acceptableRelativeError(1.0e-5f); From 6dfbf7f70a01666ef822fb63fb9c361c6d23b517 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 12 Aug 2015 14:13:28 -0700 Subject: [PATCH 4/6] coalesce scattered dupes of unit-test utilities --- tests/GLMTestUtils.h | 34 +++++++++++++++++++ tests/QTestExtensions.h | 21 ++++++++++++ .../animation/src/RotationConstraintTests.cpp | 26 -------------- tests/shared/src/AngularConstraintTests.cpp | 10 ++---- tests/shared/src/GeometryUtilTests.cpp | 7 ---- tests/shared/src/MovingMinMaxAvgTests.cpp | 5 +++ tests/shared/src/MovingMinMaxAvgTests.h | 9 ----- tests/shared/src/TransformTests.cpp | 7 ++-- tests/shared/src/TransformTests.h | 27 --------------- 9 files changed, 67 insertions(+), 79 deletions(-) diff --git a/tests/GLMTestUtils.h b/tests/GLMTestUtils.h index 6559e9f3c9..7dbc4a840f 100644 --- a/tests/GLMTestUtils.h +++ b/tests/GLMTestUtils.h @@ -14,15 +14,49 @@ #include #include +#include // Implements functionality in QTestExtensions.h for glm types +// Computes the error value between two quaternions (using glm::dot) +float getErrorDifference(const glm::quat& a, const glm::quat& b) { + return fabsf(glm::dot(a, b)) - 1.0f; +} + inline float getErrorDifference(const glm::vec3& a, const glm::vec3& b) { return glm::distance(a, b); } +inline float getErrorDifference(const glm::mat4& a, const glm::mat4& b) { + float maxDiff = 0; + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { + float diff = fabs(a[i][j] - b[i][j]); + maxDiff = std::max(diff, maxDiff); + } + } + return maxDiff; +} + inline QTextStream& operator<<(QTextStream& stream, const glm::vec3& v) { return stream << "glm::vec3 { " << v.x << ", " << v.y << ", " << v.z << " }"; } +QTextStream& operator<<(QTextStream& stream, const glm::quat& q) { + return stream << "glm::quat { " << q.x << ", " << q.y << ", " << q.z << ", " << q.w << " }"; +} + +inline QTextStream& operator<< (QTextStream& stream, const glm::mat4& matrix) { + stream << "[\n\t\t"; + stream.setFieldWidth(15); + for (int r = 0; r < 4; ++r) { + for (int c = 0; c < 4; ++c) { + stream << matrix[c][r]; + } + stream << "\n\t\t"; + } + stream.setFieldWidth(0); + stream << "]\n\t"; // hacky as hell, but this should work... + return stream; +} #endif diff --git a/tests/QTestExtensions.h b/tests/QTestExtensions.h index d1918ebed8..16e51b41ee 100644 --- a/tests/QTestExtensions.h +++ b/tests/QTestExtensions.h @@ -37,6 +37,10 @@ // +float getErrorDifference(const float& a, const float& b) { + return fabsf(a - b); +} + // Generates a QCOMPARE-style failure message that can be passed to QTest::qFail. // // Formatting looks like this: @@ -281,3 +285,20 @@ bool compareData (const char* data, const char* expectedData, size_t length) { #define COMPARE_DATA(actual, expected, length) \ QCOMPARE_WITH_EXPR((ByteData ( actual, length )), (ByteData ( expected, length )), compareData(actual, expected, length)) + + +// Produces a relative error test for float usable QCOMPARE_WITH_LAMBDA. +inline auto errorTest (float actual, float expected, float acceptableRelativeError) +-> std::function { + return [actual, expected, acceptableRelativeError] () { + if (fabsf(expected) <= acceptableRelativeError) { + return fabsf(actual - expected) < fabsf(acceptableRelativeError); + } + return fabsf((actual - expected) / expected) < fabsf(acceptableRelativeError); + }; +} + +#define QCOMPARE_WITH_RELATIVE_ERROR(actual, expected, relativeError) \ + QCOMPARE_WITH_LAMBDA(actual, expected, errorTest(actual, expected, relativeError)) + + diff --git a/tests/animation/src/RotationConstraintTests.cpp b/tests/animation/src/RotationConstraintTests.cpp index 2cdb44ee8f..4aac875f2a 100644 --- a/tests/animation/src/RotationConstraintTests.cpp +++ b/tests/animation/src/RotationConstraintTests.cpp @@ -16,34 +16,8 @@ #include #include -// HACK -- these helper functions need to be defined BEFORE including magic inside QTestExtensions.h -// TODO: fix QTestExtensions so we don't need to do this in every test. - -// Computes the error value between two quaternions (using glm::dot) -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) { - return stream << "glm::quat { " << q.x << ", " << q.y << ", " << q.z << ", " << q.w << " }"; -} - -// Produces a relative error test for float usable QCOMPARE_WITH_LAMBDA. -inline auto errorTest (float actual, float expected, float acceptableRelativeError) --> std::function { - return [actual, expected, acceptableRelativeError] () { - if (fabsf(expected) <= acceptableRelativeError) { - return fabsf(actual - expected) < fabsf(acceptableRelativeError); - } - return fabsf((actual - expected) / expected) < fabsf(acceptableRelativeError); - }; -} - #include "../QTestExtensions.h" -#define QCOMPARE_WITH_RELATIVE_ERROR(actual, expected, relativeError) \ - QCOMPARE_WITH_LAMBDA(actual, expected, errorTest(actual, expected, relativeError)) - QTEST_MAIN(RotationConstraintTests) diff --git a/tests/shared/src/AngularConstraintTests.cpp b/tests/shared/src/AngularConstraintTests.cpp index 4dcf3d7296..a711bac709 100644 --- a/tests/shared/src/AngularConstraintTests.cpp +++ b/tests/shared/src/AngularConstraintTests.cpp @@ -9,22 +9,16 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "AngularConstraintTests.h" + #include #include #include #include -#include "AngularConstraintTests.h" #include "../QTestExtensions.h" -// Computes the error value between two quaternions (using glm::dot) -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) { - return stream << "glm::quat { " << q.x << ", " << q.y << ", " << q.z << ", " << q.w << " }"; -} QTEST_MAIN(AngularConstraintTests) diff --git a/tests/shared/src/GeometryUtilTests.cpp b/tests/shared/src/GeometryUtilTests.cpp index 44a540b478..eaf1e7cd8a 100644 --- a/tests/shared/src/GeometryUtilTests.cpp +++ b/tests/shared/src/GeometryUtilTests.cpp @@ -22,13 +22,6 @@ QTEST_MAIN(GeometryUtilTests) -float getErrorDifference(const float& a, const float& b) { - return fabsf(a - b); -} - -float getErrorDifference(const glm::vec3& a, const glm::vec3& b) { - return glm::distance(a, b); -} void GeometryUtilTests::testLocalRayRectangleIntersection() { glm::vec3 xAxis(1.0f, 0.0f, 0.0f); diff --git a/tests/shared/src/MovingMinMaxAvgTests.cpp b/tests/shared/src/MovingMinMaxAvgTests.cpp index 48c3c59058..f3ba3239ee 100644 --- a/tests/shared/src/MovingMinMaxAvgTests.cpp +++ b/tests/shared/src/MovingMinMaxAvgTests.cpp @@ -13,7 +13,12 @@ #include +#include #include +#include + +#include "../QTestExtensions.h" + QTEST_MAIN(MovingMinMaxAvgTests) diff --git a/tests/shared/src/MovingMinMaxAvgTests.h b/tests/shared/src/MovingMinMaxAvgTests.h index c64b087c15..1922bd207a 100644 --- a/tests/shared/src/MovingMinMaxAvgTests.h +++ b/tests/shared/src/MovingMinMaxAvgTests.h @@ -14,15 +14,6 @@ #include -inline float getErrorDifference(float a, float b) { - return fabsf(a - b); -} - -#include "../QTestExtensions.h" - -#include "MovingMinMaxAvg.h" -#include "SharedUtil.h" - class MovingMinMaxAvgTests : public QObject { private slots: diff --git a/tests/shared/src/TransformTests.cpp b/tests/shared/src/TransformTests.cpp index be22914b9d..b936d45555 100644 --- a/tests/shared/src/TransformTests.cpp +++ b/tests/shared/src/TransformTests.cpp @@ -10,10 +10,13 @@ #include "TransformTests.h" +#include +#include + +#include #include -#include "SharedLogging.h" -#include <../QTestExtensions.h> +#include "../QTestExtensions.h" using namespace glm; diff --git a/tests/shared/src/TransformTests.h b/tests/shared/src/TransformTests.h index a4d9b2a6c0..06cdbcd3cb 100644 --- a/tests/shared/src/TransformTests.h +++ b/tests/shared/src/TransformTests.h @@ -12,33 +12,6 @@ #define hifi_TransformTests_h #include -#include -#include - -inline float getErrorDifference(const glm::mat4& a, const glm::mat4& b) { - float maxDiff = 0; - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) { - float diff = fabs(a[i][j] - b[i][j]); - maxDiff = std::max(diff, maxDiff); - } - } - return maxDiff; -} - -inline QTextStream& operator<< (QTextStream& stream, const glm::mat4& matrix) { - stream << "[\n\t\t"; - stream.setFieldWidth(15); - for (int r = 0; r < 4; ++r) { - for (int c = 0; c < 4; ++c) { - stream << matrix[c][r]; - } - stream << "\n\t\t"; - } - stream.setFieldWidth(0); - stream << "]\n\t"; // hacky as hell, but this should work... - return stream; -} class TransformTests : public QObject { Q_OBJECT From f4e77b82002a6a6012e8f3615b34924dde155d2d Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 12 Aug 2015 14:15:49 -0700 Subject: [PATCH 5/6] remove another dupe unit-test util --- tests/physics/src/BulletTestUtils.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/physics/src/BulletTestUtils.h b/tests/physics/src/BulletTestUtils.h index 01a4fd5973..9166f80ba1 100644 --- a/tests/physics/src/BulletTestUtils.h +++ b/tests/physics/src/BulletTestUtils.h @@ -23,10 +23,6 @@ // (used by QCOMPARE_WITH_RELATIVE_ERROR via QCOMPARE_WITH_LAMBDA) // (this is only used by btMatrix3x3 in MeshMassPropertiesTests.cpp, so it's only defined for the Mat3 type) -// Return the error between values a and b; used to implement QCOMPARE_WITH_ABS_ERROR -inline btScalar getErrorDifference(const btScalar& a, const btScalar& b) { - return fabs(a - b); -} // Return the error between values a and b; used to implement QCOMPARE_WITH_ABS_ERROR inline btScalar getErrorDifference(const btVector3& a, const btVector3& b) { return (a - b).length(); From f64ab8e6b08cd0c552c780e1190b148fbc9bb69d Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 12 Aug 2015 17:52:54 -0700 Subject: [PATCH 6/6] add QCOMPARE_QUATS macro for easier tests --- tests/GLMTestUtils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/GLMTestUtils.h b/tests/GLMTestUtils.h index 7dbc4a840f..f353255cc1 100644 --- a/tests/GLMTestUtils.h +++ b/tests/GLMTestUtils.h @@ -59,4 +59,8 @@ inline QTextStream& operator<< (QTextStream& stream, const glm::mat4& matrix) { stream << "]\n\t"; // hacky as hell, but this should work... return stream; } + +#define QCOMPARE_QUATS(rotationA, rotationB, angle) \ + QVERIFY(fabsf(1.0f - fabsf(glm::dot(rotationA, rotationB))) < 2.0f * sinf(angle)) + #endif