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
|
// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#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
QList<float> data;
// WHEN
FunctionRangeFinder finder(&data);
// THEN
QCOMPARE(finder.rangeSize(), 2);
QCOMPARE(finder.isAscending(), true);
QCOMPARE(finder.correlationThreshold(), 1);
}
void checkConstructionWithData_data()
{
QTest::addColumn<QList<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(QList<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<QList<float>>("x");
QTest::addColumn<QList<float>>("needles");
QTest::addColumn<QList<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(QList<float>, x);
QFETCH(QList<float>, needles);
QFETCH(QList<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"
|