Skip to content

Commit dfb1585

Browse files
committedNov 12, 2015
Bump QgsStatisticSummary test coverage
1 parent 6e1df49 commit dfb1585

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
 

‎tests/src/core/testqgsstatisticalsummary.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class TestQgsStatisticSummary: public QObject
3232
void init();// will be called before each testfunction is executed.
3333
void cleanup();// will be called after every testfunction.
3434
void stats();
35+
void individualStatCalculations_data();
36+
void individualStatCalculations();
3537
void maxMin();
3638

3739
private:
@@ -120,6 +122,51 @@ void TestQgsStatisticSummary::stats()
120122
QCOMPARE( s.interQuartileRange(), 11.0 );
121123
}
122124

125+
void TestQgsStatisticSummary::individualStatCalculations_data()
126+
{
127+
QTest::addColumn< int >( "statInt" );
128+
QTest::addColumn<double>( "expected" );
129+
130+
QTest::newRow( "count" ) << ( int )QgsStatisticalSummary::Count << 10.0;
131+
QTest::newRow( "sum" ) << ( int )QgsStatisticalSummary::Sum << 45.0;
132+
QTest::newRow( "mean" ) << ( int )QgsStatisticalSummary::Mean << 4.5;
133+
QTest::newRow( "median" ) << ( int )QgsStatisticalSummary::Median << 4.0;
134+
QTest::newRow( "st_dev" ) << ( int )QgsStatisticalSummary::StDev << 1.96214;
135+
QTest::newRow( "st_dev_sample" ) << ( int )QgsStatisticalSummary::StDevSample << 2.06828;
136+
QTest::newRow( "min" ) << ( int )QgsStatisticalSummary::Min << 2.0;
137+
QTest::newRow( "max" ) << ( int )QgsStatisticalSummary::Max << 8.0;
138+
QTest::newRow( "range" ) << ( int )QgsStatisticalSummary::Range << 6.0;
139+
QTest::newRow( "minority" ) << ( int )QgsStatisticalSummary::Minority << 2.0;
140+
QTest::newRow( "majority" ) << ( int )QgsStatisticalSummary::Majority << 3.0;
141+
QTest::newRow( "variety" ) << ( int )QgsStatisticalSummary::Variety << 5.0;
142+
QTest::newRow( "first_quartile" ) << ( int )QgsStatisticalSummary::FirstQuartile << 3.0;
143+
QTest::newRow( "third_quartile" ) << ( int )QgsStatisticalSummary::ThirdQuartile << 5.0;
144+
QTest::newRow( "iqr" ) << ( int )QgsStatisticalSummary::InterQuartileRange << 2.0;
145+
}
146+
147+
void TestQgsStatisticSummary::individualStatCalculations()
148+
{
149+
//tests calculation of statistics one at a time, to make sure statistic calculations are not
150+
//dependant on each other
151+
152+
QList<double> values;
153+
values << 4 << 4 << 2 << 3 << 3 << 3 << 5 << 5 << 8 << 8;
154+
155+
QFETCH( int, statInt );
156+
QgsStatisticalSummary::Statistic stat = ( QgsStatisticalSummary::Statistic ) statInt;
157+
QFETCH( double, expected );
158+
159+
QgsStatisticalSummary s;
160+
s.setStatistics( stat );
161+
QCOMPARE( s.statistics(), stat );
162+
163+
s.calculate( values );
164+
QVERIFY( qgsDoubleNear( s.statistic( stat ), expected, 0.00001 ) );
165+
166+
//make sure stat has a valid display name
167+
QVERIFY( !QgsStatisticalSummary::displayName( stat ).isEmpty() );
168+
}
169+
123170
void TestQgsStatisticSummary::maxMin()
124171
{
125172
QgsStatisticalSummary s( QgsStatisticalSummary::All );

0 commit comments

Comments
 (0)
Please sign in to comment.