mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 06:37:27 +02:00
commit
44d61e44e2
3 changed files with 34 additions and 29 deletions
|
@ -34,7 +34,7 @@ static void readWriteHelper(const std::vector<bool>& src) {
|
||||||
int numBits = (int)src.size();
|
int numBits = (int)src.size();
|
||||||
int numBytes = calcBitVectorSize(numBits);
|
int numBytes = calcBitVectorSize(numBits);
|
||||||
uint8_t* bytes = new uint8_t[numBytes];
|
uint8_t* bytes = new uint8_t[numBytes];
|
||||||
memset(bytes, numBytes, sizeof(uint8_t));
|
memset(bytes, 0, numBytes);
|
||||||
int numBytesWritten = writeBitVector(bytes, numBits, [&](int i) {
|
int numBytesWritten = writeBitVector(bytes, numBits, [&](int i) {
|
||||||
return src[i];
|
return src[i];
|
||||||
});
|
});
|
||||||
|
@ -53,6 +53,8 @@ static void readWriteHelper(const std::vector<bool>& src) {
|
||||||
bool b = dst[i];
|
bool b = dst[i];
|
||||||
QCOMPARE(a, b);
|
QCOMPARE(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete[] bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitVectorHelperTests::readWriteTest() {
|
void BitVectorHelperTests::readWriteTest() {
|
||||||
|
|
|
@ -132,6 +132,11 @@ void FileCacheTests::testFreeSpacePreservation() {
|
||||||
cache->setMinFreeSize(targetFreeSpace);
|
cache->setMinFreeSize(targetFreeSpace);
|
||||||
QCOMPARE(cache->getNumCachedFiles(), (size_t)5);
|
QCOMPARE(cache->getNumCachedFiles(), (size_t)5);
|
||||||
QCOMPARE(cache->getNumTotalFiles(), (size_t)5);
|
QCOMPARE(cache->getNumTotalFiles(), (size_t)5);
|
||||||
|
qDebug() << "Free space: " << getFreeSpace();
|
||||||
|
qDebug() << "Target : " << targetFreeSpace;
|
||||||
|
|
||||||
|
qInfo() << "The following test may fail if free disk space was changed by another program during the test's runtime";
|
||||||
|
|
||||||
QVERIFY(getFreeSpace() >= targetFreeSpace);
|
QVERIFY(getFreeSpace() >= targetFreeSpace);
|
||||||
for (int i = 0; i < 95; ++i) {
|
for (int i = 0; i < 95; ++i) {
|
||||||
std::string key = getFileKey(i);
|
std::string key = getFileKey(i);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <QtCore/QQueue>
|
#include <QtCore/QQueue>
|
||||||
#include <test-utils/GLMTestUtils.h>
|
#include <test-utils/GLMTestUtils.h>
|
||||||
#include <test-utils/QTestExtensions.h>
|
#include <test-utils/QTestExtensions.h>
|
||||||
|
#include <QRandomGenerator64>
|
||||||
|
|
||||||
QTEST_MAIN(MovingPercentileTests)
|
QTEST_MAIN(MovingPercentileTests)
|
||||||
|
|
||||||
|
@ -41,70 +42,67 @@ void MovingPercentileTests::testRunningMedian() {
|
||||||
|
|
||||||
|
|
||||||
int64_t MovingPercentileTests::random() {
|
int64_t MovingPercentileTests::random() {
|
||||||
return ((int64_t) rand() << 48) ^
|
return QRandomGenerator64::global()->generate();
|
||||||
((int64_t) rand() << 32) ^
|
|
||||||
((int64_t) rand() << 16) ^
|
|
||||||
((int64_t) rand());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovingPercentileTests::testRunningMinForN (int n) {
|
void MovingPercentileTests::testRunningMinForN (int n) {
|
||||||
// Stores the last n samples
|
// Stores the last n samples
|
||||||
QQueue<int64_t> samples;
|
QQueue<int64_t> samples;
|
||||||
|
|
||||||
MovingPercentile movingMin (n, 0.0f);
|
MovingPercentile movingMin (n, 0.0f);
|
||||||
|
|
||||||
for (int s = 0; s < 3 * n; ++s) {
|
for (int s = 0; s < 3 * n; ++s) {
|
||||||
int64_t sample = random();
|
int64_t sample = random();
|
||||||
|
|
||||||
samples.push_back(sample);
|
samples.push_back(sample);
|
||||||
if (samples.size() > n)
|
if (samples.size() > n)
|
||||||
samples.pop_front();
|
samples.pop_front();
|
||||||
|
|
||||||
if (samples.size() == 0) {
|
if (samples.size() == 0) {
|
||||||
QFAIL_WITH_MESSAGE("\n\n\n\tWTF\n\tsamples.size() = " << samples.size() << ", n = " << n);
|
QFAIL_WITH_MESSAGE("\n\n\n\tWTF\n\tsamples.size() = " << samples.size() << ", n = " << n);
|
||||||
}
|
}
|
||||||
|
|
||||||
movingMin.updatePercentile(sample);
|
movingMin.updatePercentile(sample);
|
||||||
|
|
||||||
// Calculate the minimum of the moving samples
|
// Calculate the minimum of the moving samples
|
||||||
int64_t expectedMin = std::numeric_limits<int64_t>::max();
|
int64_t expectedMin = std::numeric_limits<int64_t>::max();
|
||||||
|
|
||||||
int prevSize = samples.size();
|
int prevSize = samples.size();
|
||||||
for (auto val : samples) {
|
for (auto val : samples) {
|
||||||
expectedMin = std::min(val, expectedMin);
|
expectedMin = std::min(val, expectedMin);
|
||||||
}
|
}
|
||||||
QCOMPARE(samples.size(), prevSize);
|
QCOMPARE(samples.size(), prevSize);
|
||||||
|
|
||||||
QVERIFY(movingMin.getValueAtPercentile() - expectedMin == 0L);
|
QVERIFY(movingMin.getValueAtPercentile() - expectedMin == 0L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovingPercentileTests::testRunningMaxForN (int n) {
|
void MovingPercentileTests::testRunningMaxForN (int n) {
|
||||||
|
|
||||||
// Stores the last n samples
|
// Stores the last n samples
|
||||||
QQueue<int64_t> samples;
|
QQueue<int64_t> samples;
|
||||||
|
|
||||||
MovingPercentile movingMax (n, 1.0f);
|
MovingPercentile movingMax (n, 1.0f);
|
||||||
|
|
||||||
for (int s = 0; s < 10000; ++s) {
|
for (int s = 0; s < 10000; ++s) {
|
||||||
int64_t sample = random();
|
int64_t sample = random();
|
||||||
|
|
||||||
samples.push_back(sample);
|
samples.push_back(sample);
|
||||||
if (samples.size() > n) {
|
if (samples.size() > n) {
|
||||||
samples.pop_front();
|
samples.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (samples.size() == 0) {
|
if (samples.size() == 0) {
|
||||||
QFAIL_WITH_MESSAGE("\n\n\n\tWTF\n\tsamples.size() = " << samples.size() << ", n = " << n);
|
QFAIL_WITH_MESSAGE("\n\n\n\tWTF\n\tsamples.size() = " << samples.size() << ", n = " << n);
|
||||||
}
|
}
|
||||||
|
|
||||||
movingMax.updatePercentile(sample);
|
movingMax.updatePercentile(sample);
|
||||||
|
|
||||||
// Calculate the maximum of the moving samples
|
// Calculate the maximum of the moving samples
|
||||||
int64_t expectedMax = std::numeric_limits<int64_t>::min();
|
int64_t expectedMax = std::numeric_limits<int64_t>::min();
|
||||||
for (auto val : samples)
|
for (auto val : samples)
|
||||||
expectedMax = std::max(val, expectedMax);
|
expectedMax = std::max(val, expectedMax);
|
||||||
|
|
||||||
QVERIFY(movingMax.getValueAtPercentile() - expectedMax == 0L);
|
QVERIFY(movingMax.getValueAtPercentile() - expectedMax == 0L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,34 +110,34 @@ void MovingPercentileTests::testRunningMaxForN (int n) {
|
||||||
void MovingPercentileTests::testRunningMedianForN (int n) {
|
void MovingPercentileTests::testRunningMedianForN (int n) {
|
||||||
// Stores the last n samples
|
// Stores the last n samples
|
||||||
QQueue<int64_t> samples;
|
QQueue<int64_t> samples;
|
||||||
|
|
||||||
MovingPercentile movingMedian (n, 0.5f);
|
MovingPercentile movingMedian (n, 0.5f);
|
||||||
|
|
||||||
for (int s = 0; s < 10000; ++s) {
|
for (int s = 0; s < 10000; ++s) {
|
||||||
int64_t sample = random();
|
int64_t sample = random();
|
||||||
|
|
||||||
samples.push_back(sample);
|
samples.push_back(sample);
|
||||||
if (samples.size() > n)
|
if (samples.size() > n)
|
||||||
samples.pop_front();
|
samples.pop_front();
|
||||||
|
|
||||||
if (samples.size() == 0) {
|
if (samples.size() == 0) {
|
||||||
QFAIL_WITH_MESSAGE("\n\n\n\tWTF\n\tsamples.size() = " << samples.size() << ", n = " << n);
|
QFAIL_WITH_MESSAGE("\n\n\n\tWTF\n\tsamples.size() = " << samples.size() << ", n = " << n);
|
||||||
}
|
}
|
||||||
|
|
||||||
movingMedian.updatePercentile(sample);
|
movingMedian.updatePercentile(sample);
|
||||||
auto median = movingMedian.getValueAtPercentile();
|
auto median = movingMedian.getValueAtPercentile();
|
||||||
|
|
||||||
// Check the number of samples that are > or < median
|
// Check the number of samples that are > or < median
|
||||||
int samplesGreaterThan = 0;
|
int samplesGreaterThan = 0;
|
||||||
int samplesLessThan = 0;
|
int samplesLessThan = 0;
|
||||||
|
|
||||||
for (auto value : samples) {
|
for (auto value : samples) {
|
||||||
if (value < median)
|
if (value < median)
|
||||||
++samplesGreaterThan;
|
++samplesGreaterThan;
|
||||||
else if (value > median)
|
else if (value > median)
|
||||||
++samplesLessThan;
|
++samplesLessThan;
|
||||||
}
|
}
|
||||||
|
|
||||||
QCOMPARE_WITH_LAMBDA(samplesLessThan, n / 2, [=]() {
|
QCOMPARE_WITH_LAMBDA(samplesLessThan, n / 2, [=]() {
|
||||||
return samplesLessThan <= n / 2;
|
return samplesLessThan <= n / 2;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue