@@ -32,6 +32,8 @@ class TestQgsStatisticSummary: public QObject
32
32
void init ();// will be called before each testfunction is executed.
33
33
void cleanup ();// will be called after every testfunction.
34
34
void stats ();
35
+ void individualStatCalculations_data ();
36
+ void individualStatCalculations ();
35
37
void maxMin ();
36
38
37
39
private:
@@ -120,6 +122,51 @@ void TestQgsStatisticSummary::stats()
120
122
QCOMPARE ( s.interQuartileRange (), 11.0 );
121
123
}
122
124
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
+
123
170
void TestQgsStatisticSummary::maxMin ()
124
171
{
125
172
QgsStatisticalSummary s ( QgsStatisticalSummary::All );
0 commit comments