This commit is contained in:
Seiji Emery 2015-06-29 11:29:10 -07:00
parent b47cb76e3c
commit 8e324f5de2
4 changed files with 35 additions and 39 deletions

View file

@ -160,7 +160,7 @@ inline void QTest_failWithMessage(
template <typename T, typename V> template <typename T, typename V>
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) 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( QTest_failWithMessage(
"Compared values are not the same (fuzzy compare)", "Compared values are not the same (fuzzy compare)",
actual, expected, actual_expr, expected_expr, line, file, actual, expected, actual_expr, expected_expr, line, file,

View file

@ -1,9 +1,12 @@
// //
// BulletTestUtils.h // 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 #ifndef hifi_BulletTestUtils_h

View file

@ -1,9 +1,12 @@
// //
// GlmTestUtils.h // 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 #ifndef hifi_GlmTestUtils_h

View file

@ -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, 1.0f, EPSILON);
QCOMPARE_WITH_ABS_ERROR((float) stats.getAverage(), (float) average, 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) { if ((i + 1) % INTERVAL_LENGTH == 0) {
QVERIFY(stats.getNewStatsAvailableFlag());
assert(stats.getNewStatsAvailableFlag());
stats.clearNewStatsAvailableFlag(); stats.clearNewStatsAvailableFlag();
windowMin = std::numeric_limits<quint64>::max(); windowMin = std::numeric_limits<quint64>::max();
windowMax = 0; windowMax = 0;
windowAverage = 0.0; windowAverage = 0.0;
foreach(quint64 s, windowSamples) { for (quint64 s : windowSamples) {
windowMin = std::min(windowMin, s); windowMin = std::min(windowMin, s);
windowMax = std::max(windowMax, s); windowMax = std::max(windowMax, s);
windowAverage += (double)s; windowAverage += (double)s;
} }
windowAverage /= (double)windowSamples.size(); windowAverage /= (double)windowSamples.size();
assert(stats.getWindowMin() == windowMin); QCOMPARE(stats.getWindowMin(), windowMin);
assert(stats.getWindowMax() == windowMax); QCOMPARE(stats.getWindowMax(), windowMax);
assert(fabsf((float)stats.getAverage() / (float)average - 1.0f) < EPSILON || QCOMPARE_WITH_ABS_ERROR((float)stats.getAverage(), (float)average, EPSILON);
fabsf((float)stats.getAverage() - (float)average) < EPSILON);
} else { } else {
assert(!stats.getNewStatsAvailableFlag()); QVERIFY(!stats.getNewStatsAvailableFlag());
} }
} }
} }
@ -134,31 +125,30 @@ void MovingMinMaxAvgTests::testInt() {
average = (average * totalSamples + sample) / (totalSamples + 1); average = (average * totalSamples + sample) / (totalSamples + 1);
totalSamples++; totalSamples++;
assert(stats.getMin() == min); QCOMPARE(stats.getMin(), min);
assert(stats.getMax() == max); QCOMPARE(stats.getMax(), max);
assert(fabsf((float)stats.getAverage() / (float)average - 1.0f) < EPSILON); QCOMPARE_WITH_ABS_ERROR((float)stats.getAverage(), (float)average, EPSILON);
if ((i + 1) % INTERVAL_LENGTH == 0) { if ((i + 1) % INTERVAL_LENGTH == 0) {
assert(stats.getNewStatsAvailableFlag()); QVERIFY(stats.getNewStatsAvailableFlag());
stats.clearNewStatsAvailableFlag(); stats.clearNewStatsAvailableFlag();
windowMin = std::numeric_limits<int>::max(); windowMin = std::numeric_limits<int>::max();
windowMax = 0; windowMax = 0;
windowAverage = 0.0; windowAverage = 0.0;
foreach(int s, windowSamples) { for (int s : windowSamples) {
windowMin = std::min(windowMin, s); windowMin = std::min(windowMin, s);
windowMax = std::max(windowMax, s); windowMax = std::max(windowMax, s);
windowAverage += (double)s; windowAverage += (double)s;
} }
windowAverage /= (double)windowSamples.size(); windowAverage /= (double)windowSamples.size();
assert(stats.getWindowMin() == windowMin); QCOMPARE(stats.getWindowMin(), windowMin);
assert(stats.getWindowMax() == windowMax); QCOMPARE(stats.getWindowMax(), windowMax);
assert(fabsf((float)stats.getAverage() / (float)average - 1.0f) < EPSILON); QCOMPARE_WITH_ABS_ERROR((float)stats.getAverage(), (float)average, EPSILON);
} else { } else {
assert(!stats.getNewStatsAvailableFlag()); QVERIFY(!stats.getNewStatsAvailableFlag());
} }
} }
} }
@ -198,31 +188,31 @@ void MovingMinMaxAvgTests::testFloat() {
average = (average * totalSamples + (double)sample) / (totalSamples + 1); average = (average * totalSamples + (double)sample) / (totalSamples + 1);
totalSamples++; totalSamples++;
assert(stats.getMin() == min); QCOMPARE(stats.getMin(), min);
assert(stats.getMax() == max); QCOMPARE(stats.getMax(), max);
assert(fabsf((float)stats.getAverage() / (float)average - 1.0f) < EPSILON); QCOMPARE_WITH_ABS_ERROR((float)stats.getAverage(), (float)average, EPSILON);
if ((i + 1) % INTERVAL_LENGTH == 0) { if ((i + 1) % INTERVAL_LENGTH == 0) {
assert(stats.getNewStatsAvailableFlag()); QVERIFY(stats.getNewStatsAvailableFlag());
stats.clearNewStatsAvailableFlag(); stats.clearNewStatsAvailableFlag();
windowMin = std::numeric_limits<float>::max(); windowMin = std::numeric_limits<float>::max();
windowMax = 0; windowMax = 0;
windowAverage = 0.0; windowAverage = 0.0;
foreach(float s, windowSamples) { for (float s : windowSamples) {
windowMin = std::min(windowMin, s); windowMin = std::min(windowMin, s);
windowMax = std::max(windowMax, s); windowMax = std::max(windowMax, s);
windowAverage += (double)s; windowAverage += (double)s;
} }
windowAverage /= (double)windowSamples.size(); windowAverage /= (double)windowSamples.size();
assert(stats.getWindowMin() == windowMin); QCOMPARE(stats.getWindowMin(), windowMin);
assert(stats.getWindowMax() == windowMax); QCOMPARE(stats.getWindowMax(), windowMax);
assert(fabsf((float)stats.getAverage() / (float)average - 1.0f) < EPSILON); QCOMPARE_WITH_ABS_ERROR((float)stats.getAverage(), (float)average, EPSILON);
} else { } else {
assert(!stats.getNewStatsAvailableFlag()); QVERIFY(!stats.getNewStatsAvailableFlag());
} }
} }
} }