1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/****************************************************************************
**
** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtTest/QTest>
#include <private/functionrangefinder_p.h>
using namespace Qt3DAnimation::Animation;
class tst_FunctionRangeFinder : public QObject
{
Q_OBJECT
private Q_SLOTS:
void checkDefaultConstruction()
{
// GIVEN
QVector<float> data;
// WHEN
FunctionRangeFinder finder(data);
// THEN
QCOMPARE(finder.rangeSize(), 2);
QCOMPARE(finder.isAscending(), true);
QCOMPARE(finder.correlationThreshold(), 1);
}
void checkConstructionWithData_data()
{
QTest::addColumn<QVector<float>>("x");
QTest::addColumn<int>("correlationThreshold");
QTest::addColumn<bool>("ascending");
QVector<float> data = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f };
int correlationThreshold = 1;
bool ascending = true;
QTest::newRow("10 entries, ascending") << data << correlationThreshold << ascending;
data.clear();
data.resize(10000);
for (int i = 0; i < 10000; ++i)
data[i] = float(i);
ascending = true;
correlationThreshold = std::pow(float(10000), 0.25f);
QTest::newRow("10k entries, ascending") << data << correlationThreshold << ascending;
data.clear();
data.resize(10000);
for (int i = 0; i < 10000; ++i)
data[10000 - i - 1] = float(i);
ascending = false;
correlationThreshold = std::pow(float(10000), 0.25f);
QTest::newRow("10k entries, descending") << data << correlationThreshold << ascending;
data.clear();
}
void checkConstructionWithData()
{
// GIVEN
QFETCH(QVector<float>, x);
QFETCH(int, correlationThreshold);
QFETCH(bool, ascending);
// WHEN
FunctionRangeFinder finder(x);
// THEN
QCOMPARE(finder.rangeSize(), 2);
QCOMPARE(finder.isAscending(), ascending);
QCOMPARE(finder.correlationThreshold(), correlationThreshold);
}
void checkFindLowerBound_data()
{
QTest::addColumn<QVector<float>>("x");
QTest::addColumn<QVector<float>>("needles");
QTest::addColumn<QVector<int>>("lowerBounds");
QVector<float> data = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f };
QVector<float> needles = { 2.5f };
QVector<int> lowerBounds = { 1 };
QTest::newRow("10 entries, ascending") << data << needles << lowerBounds;
data.clear();
needles.clear();
lowerBounds.clear();
data.resize(10000);
for (int i = 0; i < 10000; ++i)
data[i] = float(i);
needles.push_back(23.75f);
lowerBounds.push_back(23);
needles.push_back(500.03f);
lowerBounds.push_back(500);
needles.push_back(500.2f);
lowerBounds.push_back(500);
needles.push_back(501.4f); // Will trigger hunt codepath as previous test is correlated
lowerBounds.push_back(501);
needles.push_back(3405.123f);
lowerBounds.push_back(3405);
QTest::newRow("10k entries, ascending") << data << needles << lowerBounds;
data.clear();
needles.clear();
lowerBounds.clear();
data.resize(10);
for (int i = 0; i < 10; ++i)
data[10 - i - 1] = float(i);
needles.push_back(8.1f);
lowerBounds.push_back(0);
needles.push_back(7.2f);
lowerBounds.push_back(1);
needles.push_back(0.5f);
lowerBounds.push_back(8);
QTest::newRow("10 entries, descending") << data << needles << lowerBounds;
data.clear();
}
void checkFindLowerBound()
{
// GIVEN
QFETCH(QVector<float>, x);
QFETCH(QVector<float>, needles);
QFETCH(QVector<int>, lowerBounds);
FunctionRangeFinder finder(x);
for (int i = 0; i < needles.size(); ++i) {
// WHEN
int result = finder.findLowerBound(needles[i]);
// THEN
QCOMPARE(result, lowerBounds[i]);
}
}
};
QTEST_APPLESS_MAIN(tst_FunctionRangeFinder)
#include "tst_functionrangefinder.moc"
|