diff --git a/tests/QTestExtensions.h b/tests/QTestExtensions.h index 69b911cb47..b2b2cd8e00 100644 --- a/tests/QTestExtensions.h +++ b/tests/QTestExtensions.h @@ -160,7 +160,7 @@ inline void QTest_failWithMessage( template 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 (getErrorDifference(actual, expected) > epsilon) { + if (abs(getErrorDifference(actual, expected)) > abs(epsilon)) { QTest_failWithMessage( "Compared values are not the same (fuzzy compare)", actual, expected, actual_expr, expected_expr, line, file, diff --git a/tests/physics/src/BulletTestUtils.h b/tests/physics/src/BulletTestUtils.h index 65b400a3bc..1c3d0b6610 100644 --- a/tests/physics/src/BulletTestUtils.h +++ b/tests/physics/src/BulletTestUtils.h @@ -1,9 +1,12 @@ // // BulletTestUtils.h -// hifi +// tests/physics/src // -// Created by Seiji Emery on 6/22/15. +// Created by Seiji Emery on 6/22/15 +// Copyright 2015 High Fidelity, Inc. // +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #ifndef hifi_BulletTestUtils_h diff --git a/tests/physics/src/GlmTestUtils.h b/tests/physics/src/GlmTestUtils.h index a1a5434d72..6d56ecb822 100644 --- a/tests/physics/src/GlmTestUtils.h +++ b/tests/physics/src/GlmTestUtils.h @@ -1,9 +1,12 @@ // // GlmTestUtils.h -// hifi +// tests/physics/src // -// Created by Seiji Emery on 6/22/15. +// Created by Seiji Emery on 6/22/15 +// Copyright 2015 High Fidelity, Inc. // +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #ifndef hifi_GlmTestUtils_h diff --git a/tests/shared/src/MovingMinMaxAvgTests.cpp b/tests/shared/src/MovingMinMaxAvgTests.cpp index b96d84df61..48c3c59058 100644 --- a/tests/shared/src/MovingMinMaxAvgTests.cpp +++ b/tests/shared/src/MovingMinMaxAvgTests.cpp @@ -67,34 +67,25 @@ void MovingMinMaxAvgTests::testQuint64() { 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 -// ) < EPSILON || -// fabsf( -// (float)stats.getAverage() - (float)average) < EPSILON); - if ((i + 1) % INTERVAL_LENGTH == 0) { - - assert(stats.getNewStatsAvailableFlag()); + QVERIFY(stats.getNewStatsAvailableFlag()); stats.clearNewStatsAvailableFlag(); windowMin = std::numeric_limits::max(); windowMax = 0; windowAverage = 0.0; - foreach(quint64 s, windowSamples) { + for (quint64 s : windowSamples) { windowMin = std::min(windowMin, s); windowMax = std::max(windowMax, s); windowAverage += (double)s; } windowAverage /= (double)windowSamples.size(); - assert(stats.getWindowMin() == windowMin); - assert(stats.getWindowMax() == windowMax); - assert(fabsf((float)stats.getAverage() / (float)average - 1.0f) < EPSILON || - fabsf((float)stats.getAverage() - (float)average) < EPSILON); - + QCOMPARE(stats.getWindowMin(), windowMin); + QCOMPARE(stats.getWindowMax(), windowMax); + QCOMPARE_WITH_ABS_ERROR((float)stats.getAverage(), (float)average, EPSILON); } else { - assert(!stats.getNewStatsAvailableFlag()); + QVERIFY(!stats.getNewStatsAvailableFlag()); } } } @@ -134,31 +125,30 @@ void MovingMinMaxAvgTests::testInt() { average = (average * totalSamples + sample) / (totalSamples + 1); totalSamples++; - assert(stats.getMin() == min); - assert(stats.getMax() == max); - assert(fabsf((float)stats.getAverage() / (float)average - 1.0f) < EPSILON); + QCOMPARE(stats.getMin(), min); + QCOMPARE(stats.getMax(), max); + QCOMPARE_WITH_ABS_ERROR((float)stats.getAverage(), (float)average, EPSILON); if ((i + 1) % INTERVAL_LENGTH == 0) { - assert(stats.getNewStatsAvailableFlag()); + QVERIFY(stats.getNewStatsAvailableFlag()); stats.clearNewStatsAvailableFlag(); windowMin = std::numeric_limits::max(); windowMax = 0; windowAverage = 0.0; - foreach(int s, windowSamples) { + for (int s : windowSamples) { windowMin = std::min(windowMin, s); windowMax = std::max(windowMax, s); windowAverage += (double)s; } windowAverage /= (double)windowSamples.size(); - assert(stats.getWindowMin() == windowMin); - assert(stats.getWindowMax() == windowMax); - assert(fabsf((float)stats.getAverage() / (float)average - 1.0f) < EPSILON); - + QCOMPARE(stats.getWindowMin(), windowMin); + QCOMPARE(stats.getWindowMax(), windowMax); + QCOMPARE_WITH_ABS_ERROR((float)stats.getAverage(), (float)average, EPSILON); } else { - assert(!stats.getNewStatsAvailableFlag()); + QVERIFY(!stats.getNewStatsAvailableFlag()); } } } @@ -198,31 +188,31 @@ void MovingMinMaxAvgTests::testFloat() { average = (average * totalSamples + (double)sample) / (totalSamples + 1); totalSamples++; - assert(stats.getMin() == min); - assert(stats.getMax() == max); - assert(fabsf((float)stats.getAverage() / (float)average - 1.0f) < EPSILON); + QCOMPARE(stats.getMin(), min); + QCOMPARE(stats.getMax(), max); + QCOMPARE_WITH_ABS_ERROR((float)stats.getAverage(), (float)average, EPSILON); if ((i + 1) % INTERVAL_LENGTH == 0) { - assert(stats.getNewStatsAvailableFlag()); + QVERIFY(stats.getNewStatsAvailableFlag()); stats.clearNewStatsAvailableFlag(); windowMin = std::numeric_limits::max(); windowMax = 0; windowAverage = 0.0; - foreach(float s, windowSamples) { + for (float s : windowSamples) { windowMin = std::min(windowMin, s); windowMax = std::max(windowMax, s); windowAverage += (double)s; } windowAverage /= (double)windowSamples.size(); - assert(stats.getWindowMin() == windowMin); - assert(stats.getWindowMax() == windowMax); - assert(fabsf((float)stats.getAverage() / (float)average - 1.0f) < EPSILON); + QCOMPARE(stats.getWindowMin(), windowMin); + QCOMPARE(stats.getWindowMax(), windowMax); + QCOMPARE_WITH_ABS_ERROR((float)stats.getAverage(), (float)average, EPSILON); } else { - assert(!stats.getNewStatsAvailableFlag()); + QVERIFY(!stats.getNewStatsAvailableFlag()); } } }