Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Telemetry
KUserFeedback
Commits
b8db8f73
Commit
b8db8f73
authored
Dec 18, 2016
by
Volker Krause
Browse files
Add unit test for numeric aggregation model
parent
8ae5ae18
Changes
7
Hide whitespace changes
Inline
Side-by-side
analyzer/CMakeLists.txt
View file @
b8db8f73
...
...
@@ -13,6 +13,7 @@ set(analyzer_lib_srcs
model/categoryaggregationmodel.cpp
model/datamodel.cpp
model/numericaggregationmodel.cpp
model/productmodel.cpp
model/schemamodel.cpp
model/surveymodel.cpp
...
...
@@ -31,7 +32,6 @@ set(analyzer_srcs
connectdialog.cpp
main.cpp
mainwindow.cpp
numericaggregationmodel.cpp
ratiosetaggregationmodel.cpp
analytics/analyticsview.cpp
...
...
analyzer/analytics/analyticsview.cpp
View file @
b8db8f73
...
...
@@ -20,11 +20,11 @@
#include "aggregateddatamodel.h"
#include "chart.h"
#include "numericaggregationmodel.h"
#include "ratiosetaggregationmodel.h"
#include <model/categoryaggregationmodel.h>
#include <model/datamodel.h>
#include <model/numericaggregationmodel.h>
#include <model/timeaggregationmodel.h>
#include <rest/restapi.h>
#include <core/sample.h>
...
...
@@ -139,7 +139,7 @@ void AnalyticsView::setProduct(const Product& product)
{
auto
model
=
new
NumericAggregationModel
(
this
);
model
->
setSourceModel
(
m_timeAggregationModel
);
model
->
setAggregationValue
(
schemaEntry
.
name
());
model
->
setAggregationValue
(
schemaEntry
.
name
()
+
QLatin1Char
(
'.'
)
+
schemaEntry
.
elements
().
at
(
0
).
name
()
);
m_aggregationModels
.
push_back
(
model
);
m_aggregatedDataModel
->
addSourceModel
(
model
,
schemaEntry
.
name
());
ui
->
chartType
->
addItem
(
schemaEntry
.
name
(),
QVariant
::
fromValue
(
model
));
...
...
analyzer/chart.cpp
View file @
b8db8f73
...
...
@@ -16,8 +16,9 @@
*/
#include "chart.h"
#include "numericaggregationmodel.h"
#include <model/categoryaggregationmodel.h>
#include <model/numericaggregationmodel.h>
#include <model/timeaggregationmodel.h>
#include <QtCharts/QAreaSeries>
...
...
analyzer/numericaggregationmodel.cpp
→
analyzer/
model/
numericaggregationmodel.cpp
View file @
b8db8f73
File moved
analyzer/numericaggregationmodel.h
→
analyzer/
model/
numericaggregationmodel.h
View file @
b8db8f73
...
...
@@ -33,8 +33,8 @@ public:
void
setSourceModel
(
QAbstractItemModel
*
model
);
void
setAggregationValue
(
const
QString
&
aggrValue
);
int
rowCount
(
const
QModelIndex
&
parent
)
const
override
;
int
columnCount
(
const
QModelIndex
&
parent
)
const
override
;
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
()
)
const
override
;
int
columnCount
(
const
QModelIndex
&
parent
=
QModelIndex
()
)
const
override
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
override
;
QVariant
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
)
const
override
;
...
...
tests/auto/CMakeLists.txt
View file @
b8db8f73
...
...
@@ -45,6 +45,10 @@ add_executable(categoryaggregationmodeltest categoryaggregationmodeltest.cpp)
target_link_libraries
(
categoryaggregationmodeltest UserFeedbackTestUtils Qt5::Test
)
add_test
(
NAME categoryaggregationmodeltest COMMAND categoryaggregationmodeltest
)
add_executable
(
numericaggregationmodeltest numericaggregationmodeltest.cpp
)
target_link_libraries
(
numericaggregationmodeltest UserFeedbackTestUtils Qt5::Test
)
add_test
(
NAME numericaggregationmodeltest COMMAND numericaggregationmodeltest
)
set
(
php_test_srcs
utilstest.php
schemaentrytest.php
...
...
tests/auto/numericaggregationmodeltest.cpp
0 → 100644
View file @
b8db8f73
/*
Copyright (C) 2016 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <analyzer/model/numericaggregationmodel.h>
#include <analyzer/model/datamodel.h>
#include <analyzer/model/timeaggregationmodel.h>
#include <analyzer/core/sample.h>
#include <analyzer/core/schemaentrytemplates.h>
#include <3rdparty/qt/modeltest.h>
#include <QDebug>
#include <QtTest/qtest.h>
#include <QObject>
#include <QStandardPaths>
using
namespace
UserFeedback
::
Analyzer
;
class
NumericAggregationModelTest
:
public
QObject
{
Q_OBJECT
private
slots
:
void
initTestCase
()
{
Q_INIT_RESOURCE
(
schemaentrytemplates
);
QStandardPaths
::
setTestModeEnabled
(
true
);
}
void
testEmptyModel
()
{
NumericAggregationModel
model
;
ModelTest
modelTest
(
&
model
);
model
.
setAggregationValue
(
QString
());
model
.
setAggregationValue
(
QLatin1String
(
"usageTime.value"
));
TimeAggregationModel
timeModel
;
model
.
setSourceModel
(
&
timeModel
);
DataModel
srcModel
;
timeModel
.
setSourceModel
(
&
srcModel
);
srcModel
.
setProduct
({});
QCOMPARE
(
model
.
rowCount
(),
0
);
QCOMPARE
(
model
.
columnCount
(),
6
);
Product
p
;
p
.
setSchema
(
SchemaEntryTemplates
::
availableTemplates
());
p
.
setName
(
QStringLiteral
(
"org.kde.UserFeedback.UnitTest"
));
srcModel
.
setProduct
(
p
);
QCOMPARE
(
model
.
columnCount
(),
6
);
QCOMPARE
(
model
.
rowCount
(),
0
);
}
void
testModelContent
()
{
NumericAggregationModel
model
;
ModelTest
modelTest
(
&
model
);
model
.
setAggregationValue
(
QLatin1String
(
"usageTime.value"
));
TimeAggregationModel
timeModel
;
model
.
setSourceModel
(
&
timeModel
);
DataModel
srcModel
;
timeModel
.
setSourceModel
(
&
srcModel
);
timeModel
.
setAggregationMode
(
TimeAggregationModel
::
AggregateDay
);
Product
p
;
p
.
setSchema
(
SchemaEntryTemplates
::
availableTemplates
());
p
.
setName
(
QStringLiteral
(
"org.kde.UserFeedback.UnitTest"
));
srcModel
.
setProduct
(
p
);
auto
samples
=
Sample
::
fromJson
(
R"([
{ "timestamp": "2016-11-26 12:00:00" },
{ "timestamp": "2016-11-27 12:00:00", "usageTime": { "value": "1.0" } },
{ "timestamp": "2016-11-27 12:00:00", "usageTime": { "value": "2.0" } },
{ "timestamp": "2016-11-27 12:00:00", "usageTime": { "value": "3.0" } },
{ "timestamp": "2016-11-27 12:00:00", "usageTime": { "value": "0.0" } },
{ "timestamp": "2016-11-27 12:00:00", "usageTime": { "value": "4.0" } },
{ "timestamp": "2016-11-27 12:00:00", "usageTime": { "value": "5.0" } },
{ "timestamp": "2016-11-28 12:00:00", "usageTime": { "value": "1.0" } },
{ "timestamp": "2016-11-28 12:00:00", "usageTime": { "value": "2.0" } },
{ "timestamp": "2016-11-28 12:00:00" }
])"
,
p
);
QCOMPARE
(
samples
.
size
(),
10
);
srcModel
.
setSamples
(
samples
);
QCOMPARE
(
model
.
columnCount
(),
6
);
QCOMPARE
(
model
.
headerData
(
1
,
Qt
::
Horizontal
,
Qt
::
DisplayRole
).
toString
(),
QLatin1String
(
"Lower Extreme"
));
QCOMPARE
(
model
.
headerData
(
3
,
Qt
::
Horizontal
,
Qt
::
DisplayRole
).
toString
(),
QLatin1String
(
"Median"
));
QCOMPARE
(
model
.
headerData
(
5
,
Qt
::
Horizontal
,
Qt
::
DisplayRole
).
toString
(),
QLatin1String
(
"Upper Extreme"
));
QCOMPARE
(
model
.
rowCount
(),
3
);
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-11-26"
));
QCOMPARE
(
model
.
index
(
0
,
1
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
0.0
);
QCOMPARE
(
model
.
index
(
0
,
2
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
0.0
);
QCOMPARE
(
model
.
index
(
0
,
3
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
0.0
);
QCOMPARE
(
model
.
index
(
0
,
4
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
0.0
);
QCOMPARE
(
model
.
index
(
0
,
5
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
0.0
);
QCOMPARE
(
model
.
index
(
1
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-11-27"
));
QCOMPARE
(
model
.
index
(
1
,
1
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
0.0
);
QCOMPARE
(
model
.
index
(
1
,
2
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
1.0
);
QCOMPARE
(
model
.
index
(
1
,
3
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
3.0
);
QCOMPARE
(
model
.
index
(
1
,
4
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
4.0
);
QCOMPARE
(
model
.
index
(
1
,
5
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
5.0
);
QCOMPARE
(
model
.
index
(
2
,
0
).
data
(
TimeAggregationModel
::
TimeDisplayRole
).
toString
(),
QLatin1String
(
"2016-11-28"
));
QCOMPARE
(
model
.
index
(
2
,
1
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
0.0
);
QCOMPARE
(
model
.
index
(
2
,
2
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
0.0
);
QCOMPARE
(
model
.
index
(
2
,
3
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
1.0
);
QCOMPARE
(
model
.
index
(
2
,
4
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
2.0
);
QCOMPARE
(
model
.
index
(
2
,
5
).
data
(
Qt
::
DisplayRole
).
toDouble
(),
2.0
);
QCOMPARE
(
model
.
index
(
0
,
0
).
data
(
TimeAggregationModel
::
MaximumValueRole
).
toDouble
(),
5.0
);
}
};
QTEST_MAIN
(
NumericAggregationModelTest
)
#include "numericaggregationmodeltest.moc"
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment